Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl : Is there a better way to print a substring value ?

Status
Not open for further replies.

brittany1

Technical User
Aug 17, 2007
12
US
Perl:
print substr($thevar,0,-4);
 print "\n";
The above gives me what I want. But it seems that theres a better way.

Perl:
print "\n", substr($thevar,0,-4);

Doesnt give me what I want.

Thanks in advance for any help !!
 
I am not sure I see what the difference is. What is it that you want?
 
Code:
print "\n", substr($thevar,0,-4);
is printing in list context so outputs the newline then the substring, where as
Code:
print substr($thevar,0,-4);
 print "\n";
is two separate statements executed linearly (one after the other), so the newline is output second after the substring.



"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top