Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Syntactic Confectionery Delight
 
PerlMonks  

How to replace the cut command from cshell in Perl

by juo (Curate)
on Jan 19, 2001 at 16:12 UTC ( [id://53020]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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 kschwab (Vicar) on Jan 19, 2001 at 16:22 UTC
Re: How to replace the cut command from cshell in Perl
by davorg (Chancellor) on Jan 19, 2001 at 16: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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://53020]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.