CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
$_

 



awaiz
Novice

Aug 10, 2009, 12:03 AM

Post #1 of 5 (727 views)
$_ Can't Post

Hello,

my perl program

..................

my $new=$_;

print "$new\n"

.............

what should the above print statement ?

regards,

Awaiz.


spider
User


Aug 10, 2009, 1:29 AM

Post #2 of 5 (722 views)
Re: [awaiz] $_ [In reply to] Can't Post

What are you trying to do?
This does not make any sence, without anything before it.

Where should $_ get its value from?

By the way you ar missing the ending semicolon (;) behind the print statement.


vikas.deep
User

Aug 10, 2009, 4:26 AM

Post #3 of 5 (714 views)
Re: [spider] $_ [In reply to] Can't Post


Quote
By the way you ar missing the ending semicolon (;) behind the print statement.

No he (Original Poster) is right the last print statement does not needs semicolon. YOu try it put something valid in $new say 'perl' and then print it you will get perl
perfectly normal

Quote
-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"


spider
User


Aug 10, 2009, 4:41 AM

Post #4 of 5 (710 views)
Re: [vikas.deep] $_ [In reply to] Can't Post

Ok, it works, but that does not make it correct.
The only reason it is working is because it is the last action of the script.
If he wanted the script to do anything after the print, it would fail because perl are not done with the print.

Ex:

Code
my $new = "perl" ; 
print "$new"

Will print out perl, but the next one will fail with a syntax error because the second my is noe a vaild parameter to the first print.

Code
my $new = "perl" ; 
print "$new\n"
my $new2 = "perl" ;
print "$new2\n"



KevinR
Veteran


Aug 10, 2009, 9:48 AM

Post #5 of 5 (701 views)
Re: [awaiz] $_ [In reply to] Can't Post


In Reply To
Hello,

my perl program

..................

my $new=$_;

print "$new\n"

.............

what should the above print statement ?

regards,

Awaiz.


It will (not should) print nothing.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives