Regular expression

Discussion in 'Perl Misc' started by a246456, Sep 23, 2004.

  1. a246456

    a246456 Guest

    Hello,
    I am processing a list from a file which contains different paths to be
    processed. for example:
    /apps/oracle/a.htm
    /apps/user/bin/a.gif
    /apps/export/images/sdsd.gif
    /apps/images/client/list/wqerew.gif
    I want to split the filename and the path. Then i can use the path as input
    to fetch the file from a remote machine through ftp.. I am able to get the
    filename, but i am not able to get the full path with the slashes in it..
    Thanks for your help...
    ----------------------------------------------------------------------------
    --------------
    open(LST, "content.txt") || die "File content.txt not found. $!\n";
    open(FAIL, ">fail.txt");
    $cont=<LST>;
    chomp($cont);
    while($cont ne "")
    {
    @line=split('/', $cont);
    $file=pop(@line);
    print "File Name is $file\n";
    $cont=<LST>;
    }
    close LST;
     
    a246456, Sep 23, 2004
    #1
    1. Advertising

  2. a246456 wrote:

    > Hello,
    > I am processing a list from a file which contains different paths to be
    > processed. for example:
    > /apps/oracle/a.htm
    > /apps/user/bin/a.gif
    > /apps/export/images/sdsd.gif
    > /apps/images/client/list/wqerew.gif
    > I want to split the filename and the path. Then i can use the path as input
    > to fetch the file from a remote machine through ftp.. I am able to get the
    > filename, but i am not able to get the full path with the slashes in it..
    > Thanks for your help...



    use File::Basename;
     
    mshelor[at]cpan.org, Sep 23, 2004
    #2
    1. Advertising

  3. a246456

    Abhinav Guest

    a246456 wrote:
    > Hello,
    > I am processing a list from a file which contains different paths to be
    > processed. for example:
    > /apps/oracle/a.htm
    > /apps/user/bin/a.gif
    > /apps/export/images/sdsd.gif
    > /apps/images/client/list/wqerew.gif
    > I want to split the filename and the path. Then i can use the path as input
    > to fetch the file from a remote machine through ftp.. I am able to get the
    > filename, but i am not able to get the full path with the slashes in it..
    > Thanks for your help...


    you can use the fileparse routine :

    perldoc File::Basename

    HTH
    Abhinav
     
    Abhinav, Sep 23, 2004
    #3
  4. a246456 wrote:
    > I am processing a list from a file which contains different paths
    > to be processed. for example:
    > /apps/oracle/a.htm
    > /apps/user/bin/a.gif
    > /apps/export/images/sdsd.gif
    > /apps/images/client/list/wqerew.gif
    > I want to split the filename and the path. Then i can use the path
    > as input to fetch the file from a remote machine through ftp.. I am
    > able to get the filename, but i am not able to get the full path
    > with the slashes in it..


    use File::Basename;
    open LST, "content.txt" or die "File content.txt not found. $!";
    while ( my $cont = <LST> ) {
    chomp $cont;
    my ($file, $path) = fileparse $cont;
    print "File Name is $file\n", "Path is $path\n";
    }
    close LST;

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Sep 23, 2004
    #4
  5. "a246456" <> wrote in message news:<mnB4d.43$>...
    > Hello,
    > I am processing a list from a file which contains different paths to be
    > processed. for example:
    > /apps/oracle/a.htm
    > /apps/user/bin/a.gif
    > /apps/export/images/sdsd.gif
    > /apps/images/client/list/wqerew.gif
    > I want to split the filename and the path. Then i can use the path as input
    > to fetch the file from a remote machine through ftp.. I am able to get the
    > filename, but i am not able to get the full path with the slashes in it..
    > Thanks for your help...
    > ----------------------------------------------------------------------------
    > --------------
    > open(LST, "content.txt") || die "File content.txt not found. $!\n";
    > open(FAIL, ">fail.txt");
    > $cont=<LST>;
    > chomp($cont);
    > while($cont ne "")
    > {
    > @line=split('/', $cont);
    > $file=pop(@line);
    > print "File Name is $file\n";
    > $cont=<LST>;
    > }
    > close LST;


    Look at the File::Basename module.
     
    John S. Humanski, Sep 23, 2004
    #5
  6. a246456

    Jim Keenan Guest

    "a246456" <> wrote in message news:<mnB4d.43$>...
    > Hello,
    > I am processing a list from a file which contains different paths to be
    > processed. for example:
    > /apps/oracle/a.htm
    > /apps/user/bin/a.gif
    > /apps/export/images/sdsd.gif
    > /apps/images/client/list/wqerew.gif
    > I want to split the filename and the path. Then i can use the path as input
    > to fetch the file from a remote machine through ftp.. I am able to get the
    > filename, but i am not able to get the full path with the slashes in it..
    > Thanks for your help...
    > ----------------------------------------------------------------------------
    > --------------
    > open(LST, "content.txt") || die "File content.txt not found. $!\n";
    > open(FAIL, ">fail.txt");
    > $cont=<LST>;
    > chomp($cont);
    > while($cont ne "")
    > {
    > @line=split('/', $cont);
    > $file=pop(@line);
    > print "File Name is $file\n";
    > $cont=<LST>;
    > }
    > close LST;


    1. Subject is misleading. You don't use a regular expression in code
    above; you're only using a pattern as the first argument to 'split'.

    2. But using a Perl module is a better approach:

    use File::Basename;
    use Data::Dumper;

    my @results;

    push(@results, [ dirname($_), basename($_) ]) while (<DATA>);

    print Dumper(\@results);

    __DATA__
    /apps/oracle/a.htm
    /apps/user/bin/a.gif
    /apps/export/images/sdsd.gif
    /apps/images/client/list/wqerew.gif

    For reference:

    perldoc File::Basename

    HTH!

    Jim Keenan
     
    Jim Keenan, Sep 23, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keith-Earl
    Replies:
    1
    Views:
    463
    Mary Chipman
    Jun 15, 2004
  2. VSK
    Replies:
    2
    Views:
    2,336
  3. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    863
    Alan Moore
    Dec 2, 2005
  4. GIMME
    Replies:
    3
    Views:
    11,998
    vforvikash
    Dec 29, 2008
  5. Noman Shapiro
    Replies:
    0
    Views:
    240
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page