On May 6, Zielfelder, Robert said:

>Is there a way to make Perl truncate a single scalar variable by a given
>number of characters like the unix cut command can?  For example, I have a
>scalar variable that is 7 characters long, but for another purpose I only
>want the last 5 characters of this variable.  To do this with the unix cut
>command I would issue the following line:
>
>Echo $variable | cut -c3-7

sounds like you want the substr() function.  perldoc -f substr

  $last_5_chars = substr($string, -5);

The cool thing about that is you don't need to worry about the string
length -- whether it be 7 or 100 characters, you'll get the last five.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to