For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > November 2006 > how to print "\n" in the output file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to print "\n" in the output file
Mihir Kamdar

2006-11-04, 6:56 pm

hi,

I am a beginner in Perl. I am trying to automatically generate a perl test
case file which, on executing, would return HTTP response code and response
time,etc. In the output file that I am getting I want the following line:

print "\n" ;

Any Suggestions??

thanks,
Mihir

Mazhar

2006-11-04, 6:56 pm

On 11/4/06, Mihir Kamdar <kamdarmihir06@gmail.com> wrote:
>
> hi,
>
> I am a beginner in Perl. I am trying to automatically generate a perl test
> case file which, on executing, would return HTTP response code and
> response
> time,etc. In the output file that I am getting I want the following line:
>
> print "\n" ;
>
> Any Suggestions??
>
> thanks,
> Mihir
>
> Hi,


U can keep the \n into a hash table (value) and can access the same using
its key


Regards
Mazhar

Ron Smith

2006-11-04, 6:56 pm

--- Mazhar <syedmazhar.hasan@gmail.com> wrote:
[color=darkred]
> On 11/4/06, Mihir Kamdar <kamdarmihir06@gmail.com>
> wrote:
> automatically generate a perl test
> response code and
> want the following line:
Would the following help?

perl -e 'print "\\n\n"'

Escape the backslash. This prints "\n" on a new line.


Ron Smith
gsatlarge@yahoo.com
Mihir Kamdar

2006-11-05, 3:59 am

thanks to all,

i was able to solve the problem with your guidance. The code below worked
for me:

print OUTPUTSCRIPT "print qq|\\n|; ";

Now I want to calculate the response time that web server took for a
particular request(GET/POST). My output script is something like the
following:

my $req20 = HTTP::Request->new(POST => "
http://192.168.1.170^M/vodexUi/CVodSchedularViewMgr.php ");
$req20->content_type('application/x-www-form-urlencoded');
$req20->content('strPageOp=buildQuery&strUnicastVusArr%5B%5D=regular&strUnicastUrl=rtsp%3A%2F%2F& strUnicastUrlArr%5B%5D=rtsprCPDurationSe
conds=&strCPRunName=test&strCPSavedRunsArr=test');
# Pass request to user agent & get response
my $resp20 = $browser->request($req20);
print qq|Response code is: |;print $resp20->code;
print qq|\n|;

I am using LWP::UserAgent, HTTP::Request and HTTP::Response here. How can I
calculate the response time on the basis of above data.

As always, your help appreciated,

Mihir
On 11/4/06, Ron Smith <gsatlarge@yahoo.com> wrote:
>
> --- Mazhar <syedmazhar.hasan@gmail.com> wrote:
>
> Would the following help?
>
> perl -e 'print "\\n\n"'
>
> Escape the backslash. This prints "\n" on a new line.
>
>
> Ron Smith
> gsatlarge@yahoo.com
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>


Rob Dixon

2006-11-05, 8:00 am

Mihir Kamdar wrote:
> hi,
>
> I am a beginner in Perl. I am trying to automatically generate a perl test
> case file which, on executing, would return HTTP response code and response
> time,etc. In the output file that I am getting I want the following line:
>
> print "\n" ;
>
> Any Suggestions??


print 'print "\n" ;', "\n";

Rob
Dr.Ruud

2006-11-05, 8:00 am

"Mihir Kamdar" schreef:

> print OUTPUTSCRIPT "print qq|\\n|; ";


Alternative:

print OUTPUTSCRIPT 'print q{\n}; ' ;

Why do you print a space at the end of the line?


If you need interpolation, use the "" (or qq).

print $script "print q{$^O\\n};\n" ;

Or set a variable like $LF to '\n'.

my $LF = q{\n} ;
print $script "print q{${^O}${LF}};\n" ;


Or use a heredoc:

#!/usr/bin/perl
use warnings ;
use strict ;

my $fn = 'newscript.pl' ;
open my $fh, '>', $fn or die "open '$fn': $!" ;

print $fh <<'EOS';
#!/usr/bin/perl
use warnings;
use strict;

print "$^O\n";

__END__
EOS

close $fh or die "close '$fn': $!" ;

__END__

--
Affijn, Ruud

"Gewoon is een tijger."
Dr.Ruud

2006-11-05, 8:00 am

"Dr.Ruud" schreef:

> Or set a variable like $LF to '\n'.
>
> my $LF = q{\n} ;
> print $script "print q{${^O}${LF}};\n" ;


Oops, make that last line:

print $script "print qq{$^O$LF};\n" ;

or, if you need the late OS-name:

print $script "print qq{\${^O}${LF}};\n" ;

--
Affijn, Ruud

"Gewoon is een tijger."
Robin Norwood

2006-11-05, 6:57 pm

"Mihir Kamdar" <kamdarmihir06@gmail.com> writes:

> 1. (*) text/plain
>
> hi,
>
> I am a beginner in Perl. I am trying to automatically generate a perl test
> case file which, on executing, would return HTTP response code and response
> time,etc. In the output file that I am getting I want the following line:
>
> print "\n" ;
>
> Any Suggestions??


How about :

#!/usr/bin/perl

use warnings;
use strict;

# One way
my $line = q(print "\n";) . "\n";
print $line;

# Another way:
print <<EOQ;
print "\\n";
EOQ

For more info, look in perldoc perlop for: "Quote and Quote-like
Operators"

-RN

--
Robin Norwood
Red Hat, Inc.

"The Sage does nothing, yet nothing remains undone."
-Lao Tzu, Te Tao Ching
Mihir Kamdar

2006-11-05, 9:58 pm

thanks all,

the different ways suggested by you gave me a lot of learning.

regards,
Mihir

On 11/5/06, Robin Norwood <rnorwood@redhat.com> wrote:
>
> "Mihir Kamdar" <kamdarmihir06@gmail.com> writes:
>
> test
> response
> line:
>
> How about :
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> # One way
> my $line = q(print "\n";) . "\n";
> print $line;
>
> # Another way:
> print <<EOQ;
> print "\\n";
> EOQ
>
> For more info, look in perldoc perlop for: "Quote and Quote-like
> Operators"
>
> -RN
>
> --
> Robin Norwood
> Red Hat, Inc.
>
> "The Sage does nothing, yet nothing remains undone."
> -Lao Tzu, Te Tao Ching
>


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com