[Israel.pm] how do i cut the first 2 characters/digits of a string?

Yossi Klein kleinyossi at yahoo.com
Thu Jul 15 03:11:04 PDT 2004

Or, even better

$x = substr ($str, 0, 2, '');

will chop off the first two chars from $str and assign
it to $x. I don't think that's too obfuscated :-)

If you're only interested in chopping and not getting
the 2 chars, you might consider doing:

substr ($str, 0, 2) = undef;

which I think more clearly shows that you're deleting
the first 2 chars. You can't combine like:

$x = substr ($str, 0, 2) = undef;

because $str will get chopped before the assignment to
$x and then $x will actually get the third and fourth
char (which although wrong, is pretty cool if you
think about it).


--- Gabor Szabo <gabor at pti.co.il> wrote:
> print substr($str,0,2) will get you the 2 chars
> substr($str,0,2,"") will remove the first two chars.
> Yehuda, a few notes:
> - It might be better to write your questions in the
> body of the e-mail and
>   not the subject line. Use the subject line only
> for general idea what is
>   your mail about.
> - This question (and the previous one you had)
>   could perfectly fit to the starter list too
>   http://perl.org.il/mailman/listinfo/starter
>   Your are welcome to post such questions there.
> Gabor
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl

Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!

More information about the Perl mailing list