For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > April 2007 > string manip









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author string manip
Nishi

2007-04-18, 9:58 pm

Hi:

I have a string of the form
$ARGV[0]="abc/def/ghi";

I need to strip abc to convert $ARGV[0] to
$ARGV[0]="def/ghi"

Please let me know how I can achieve it.
Thanks!

Jason Roth

2007-04-18, 9:58 pm

There are lots of ways you could accomplish this, my choice would be
something like

$ARGV[0] =~ s#^[^/]+/##;

-Jason

On 4/18/07, Nishi <nishiprafull@gmail.com> wrote:
> Hi:
>
> I have a string of the form
> $ARGV[0]="abc/def/ghi";
>
> I need to strip abc to convert $ARGV[0] to
> $ARGV[0]="def/ghi"
>
> Please let me know how I can achieve it.
> Thanks!
>

Tom Phoenix

2007-04-18, 9:58 pm

On 4/18/07, Nishi <nishiprafull@gmail.com> wrote:

> I have a string of the form
> $ARGV[0]="abc/def/ghi";
>
> I need to strip abc to convert $ARGV[0] to
> $ARGV[0]="def/ghi"
>
> Please let me know how I can achieve it.


Maybe you want one of these?

$ARGV[0] = "def/ghi" if $ARGV[0] eq "abc/def/ghi";
$ARGV[0] =~ s#abc/##;
substr($ARGV[0], 0, 4) = "";

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training
Rob Dixon

2007-04-19, 6:58 pm

Tom Phoenix wrote:
>
> On 4/18/07, Nishi <nishiprafull@gmail.com> wrote:
>
>
> Maybe you want one of these?
>
> $ARGV[0] = "def/ghi" if $ARGV[0] eq "abc/def/ghi";
> $ARGV[0] =~ s#abc/##;
> substr($ARGV[0], 0, 4) = "";


or possibly

$ARGV[0] =~ s|.*?/||;

which will remove the first element of a path whatever it contains.

Rob
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com