juo has asked for the wisdom of the Perl Monks concerning the following question:

I have a variable called : $path = c:/path1/path2/file1 Now I want to create a variable for example : $file = file1 Does anybody know how to do this in Perl. (file1 is not a fixed name but is different everytime) Pieter
  • Comment on How to replace the cut command from cshell in Perl

Replies are listed 'Best First'.
Re: How to replace the cut command from cshell in Perl
by davorg (Chancellor) on Jan 19, 2001 at 21:38 UTC

    File::Basename is the best way to go, but sometimes if I'm feeling particularly obtuse, I might use something like:</>

    my $file = (split(/\//, $path))[-1];

    I don't recommend it tho :)

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

      or:
      @parts = split(/\//); $file1 = pop @parts;
      in case the parts might be useful later, but YMMV (may want to chomp if there's a \n on there) - not wildly recommended either.

      a

Re: How to replace the cut command from cshell in Perl
by kschwab (Vicar) on Jan 19, 2001 at 21:22 UTC