Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Regular expression

Reply
Thread Tools

Regular expression

 
 
a246456
Guest
Posts: n/a
 
      09-23-2004
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;


 
Reply With Quote
 
 
 
 
mshelor[at]cpan.org
Guest
Posts: n/a
 
      09-23-2004
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;
 
Reply With Quote
 
 
 
 
Abhinav
Guest
Posts: n/a
 
      09-23-2004
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
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-23-2004
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
 
Reply With Quote
 
John S. Humanski
Guest
Posts: n/a
 
      09-23-2004
"a246456" <(E-Mail Removed)> wrote in message news:<mnB4d.43$(E-Mail Removed)>...
> 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.
 
Reply With Quote
 
Jim Keenan
Guest
Posts: n/a
 
      09-23-2004
"a246456" <(E-Mail Removed)> wrote in message news:<mnB4d.43$(E-Mail Removed)>...
> 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:umper;

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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments