pravink22
asked on
Auto filling from a notepad
Hi,
In the below script, when I tried to get input from a notepad.txt and paste it on a url, I can see only the first line of the notepad only posted, can someone help me in fixing this?
__________________________ __________ __________
use WWW::Mechanize;
$mech = WWW::Mechanize->new();
$input1 = "TITLE";
open(FILE,"notepad.txt");
@input2 = <FILE>;
$mech->get("URL");
$mech->form_with_fields((" subject"," Content")) ;
$mech->field("subject",$in put1);
$mech->field("Content",@in put2);
$mech->submit_form();
__________________________ __________ __________ ______-
In the below script, when I tried to get input from a notepad.txt and paste it on a url, I can see only the first line of the notepad only posted, can someone help me in fixing this?
__________________________
use WWW::Mechanize;
$mech = WWW::Mechanize->new();
$input1 = "TITLE";
open(FILE,"notepad.txt");
@input2 = <FILE>;
$mech->get("URL");
$mech->form_with_fields(("
$mech->field("subject",$in
$mech->field("Content",@in
$mech->submit_form();
__________________________
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I guess it doesn't matter, then. The key must have been to pass a string instead of an array. Either way, that line should just help (it shouldn't hurt).
This line is supposed to remove all the carriage returns. They're special characters, like a newline or a Tab, but Perl can deal with them using the special character "\r" (yes, backslash, then r). Just line "\n" is for a newline. This regex:
Basically, it just searches through $input2_fixed and removes all of the carriage returns. The resulting string is put back into $input2_fixed (so no temporary variable).
This line is supposed to remove all the carriage returns. They're special characters, like a newline or a Tab, but Perl can deal with them using the special character "\r" (yes, backslash, then r). Just line "\n" is for a newline. This regex:
$input2_fixed =~ s/\r//g;
Says take everything in $input2_fixed, apply a regex and apply it back to the variable "=~", the regex says to substitute "s" a carriage return (\r) with nothing (there are two slashes with nothing between them) and apply that change globally (the trailing 'g'), meaning don't just remove the *first* carriage return you find, but *all* of them.Basically, it just searches through $input2_fixed and removes all of the carriage returns. The resulting string is put back into $input2_fixed (so no temporary variable).
You can even shorten this code by doing:
$/ = undef;
open(FILE,"notepad.txt");
my $input2_fixed = <FILE>;
close FILE;
instead of current lines 4-7
ASKER
Without this also script is works gr8