Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

perl problem with input line -e

by unixguy (Acolyte)
on Feb 11, 2010 at 00:13 UTC ( #822549=perlquestion: print w/ replies, xml ) Need Help??
unixguy has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to get the first character in a line, if line has -e, its not working any help to fix this? look at the 2nd example.
1. $ echo "ella" |perl -lane 'print substr($_,0,1)' e 2. $ echo "-e" |perl -lane 'print substr($_,0,1)'
Thanks

Comment on perl problem with input line -e
Download Code
Re: perl problem with input line -e
by rubasov (Friar) on Feb 11, 2010 at 00:43 UTC
    There is nothing wrong with your perl one-liner, your usage of echo is what misleads you. Try echo "-e" alone and see that it prints only a newline. That is because echo interprets your "-e" as on option, not a string to print.

    Try this instead: printf -- "-e\n"

    The '--' signifies the end of options, anything follows that will be interpreted as an argument to print. This is the common unix way to use an argument that looks like an option.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-07-25 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls