Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Removing white-lines...

by osunderdog (Deacon)
on Apr 06, 2007 at 10:51 UTC ( #608637=note: print w/replies, xml ) Need Help??


in reply to Removing white-lines...

Just for the record, there's syntax oddity in your example code. $str =~ trim($str); isn't really doing anything. Your output from this would be:

Hello

The =~ assignment is used to assign a string to a regular expression. It is not assignment of one scalar to another. In this case, I don't think it even calls the trim function. I've modified the example to return the expected result:

use strict; sub trim($) { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; } my $str = " Hello "; $str = trim($str); print $str; #"Hello"

Hazah! I'm Employed!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2020-12-01 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (20 votes). Check out past polls.

    Notices?