Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

mechanize submission is all one line and loses line breaks reading input

by diamondsandperls (Beadle)
on Sep 21, 2012 at 16:48 UTC ( #994942=perlquestion: print w/ replies, xml ) Need Help??
diamondsandperls has asked for the wisdom of the Perl Monks concerning the following question:

Please help the scalar that is getting submitted for $input_data when this is submitted it is all one line. The file it reads in has line breaks. txtIncidentDescription is the description field that is having the issue. I am reading in the file with File::Slurp.
#!perl use strict; use warnings; use WWW::Mechanize; use Term::InKey; use Win32::Clipboard; use File::Slurp; my $ua = LWP::UserAgent->new; #DETERMINING END USER my $oldSSO = qx{whoami}; chomp $oldSSO; my ($sso) = $oldSSO =~ /.*(\w{2}\d{5})/; #PROMPTING FOR PASSWORD print "Enter Password: "; my $pass = &ReadPassword; chomp $pass; #SETTING DATA TO SUBMIT my $input_data = read_file( 'C:/temp/vpn_user.txt' ); #DECLARE URL VARIABLES my $url1 = "https://url1"; my $url2 = "https://url2"; my $url3 = "https://url3"; #TURN OFF SSL CHECKING $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; #MECHANIZE TO GET AND PRINT CONTENT my $mech = WWW::Mechanize->new(timeout => 60, autocheck => 1); #SET COOKIE JAR $mech->cookie_jar(HTTP::Cookies->new); #USER AGENT $mech->agent_alias( 'Windows IE 6' ); $mech->get($url1); $mech->form_name('Login'); $mech->field(USER => "$sso"); $mech->field(PASSWORD => "$pass"); $mech->click(); $mech->get($url2); #SET FORM VALUES $mech->form_name('frmTicketCreate'); $mech->field('ddlProducts' => 1245); $mech->field('txtIncidentDescription' => $input_data); $mech->field('ctrlAssignedGroupLookup_mTxtName' => "assigned team"); $mech->field('__EVENTTARGET', 'ctrlAssignedGroupLookup_mBtnSearch_lnkB +utton'); $mech->submit('ctrlAssignedGroupLookup_mBtnSearch_lnkButton'); my $content_login = $mech->content(); my ($number) = $content_login =~ /ctrlAssignedGroupLookup_mCBLLookupGr +oups\S value\S\S(\d+)/; #print $number, "\n"; $mech->field('ctrlAssignedGroupLookup_mCBLLookupGroups' => $number); #$mech->form_name('frmTicketCreateFileUpload'); #SUBMIT FORM $mech->form_name('frmTicketCreate'); $mech->field('__EVENTTARGET', 'btnSave_lnkButton'); $mech->submit();

Comment on mechanize submission is all one line and loses line breaks reading input
Download Code
Re: mechanize submission is all one line and loses line breaks reading input
by Kenosis (Priest) on Sep 21, 2012 at 17:17 UTC

    Have you tried the following to produce CRLF line-breaks for your multi-line description field?

    my $input_data = read_file( 'C:/temp/vpn_user.txt' ); $input_data =~ s/\n/\r\n/g;
      this got me there there; however, on things that were double spaced are now single spaced. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://994942]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-08-23 08:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (173 votes), past polls