Regular expression

A

a246456

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;
 
M

mshelor[at]cpan.org

a246456 said:
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;
 
A

Abhinav

a246456 said:
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
 
G

Gunnar Hjalmarsson

a246456 said:
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;
 
J

John S. Humanski

a246456 said:
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.
 
J

Jim Keenan

a246456 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top