Re: [PBML] Regular expressions help
>>>>> "nikhil" == nikhil deshpande <deshpandenikhils@...> writes:nikhil> $dir_path = </abc/def/ghi/pp1234220.127.116.11.jk.xyz>;
What is this? Not Perl.
Some other language?
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
- On Wed, Jul 29, 2009 at 6:45 PM, nikhil
> Now for a separate part of the same script, I want to extract only theGenerally, the best practice is to use well-tested and
> following part of the variable $dir_path and save it in some other variable:
thoroughly-designed modules to solve problems like these. For sure
you could come up with a regular expression that ought to mostly work,
but then you'll come across an edge case that you weren't expecting,
and things will break.
For instance, for this problem, I would recommend you look at the
File::Basename package, and possibly other packages available on
Get to know and love CPAN. Many people have come before you, and left
a lot of code to make your way smoother and clearer. It's only polite
to try to use what they've contributed : )
- Hi Nikhil,
hope this will resolve your problem
$dir_path = "/abc/def/ghi/pp123418.104.22.168.jk.xyz";
$filename = ($dir_path =~ /(.*)\/(.*)\/(.*)\/(.*)/);
$filename = $4;
$fileDirectory = $1."/"."$2"."/".$3;
The output of the result will be :
--- In firstname.lastname@example.org, nikhil deshpande <deshpandenikhils@...> wrote:
> Hi everyone,
> I am preparing a script to extract certain data from a file. The file is stored at the location specified
> in the variable $dir_path below. There are several such files and the data is extracted automatically as the
> script runs.
> For that purpose, I am facing following problem:
> Following is the path to the file:
> $dir_path = </abc/def/ghi/pp123422.214.171.124.jk.xyz>;
> Now for a separate part of the same script, I want to extract only the following part of
> the variable $dir_path and save it in some other variable:
> I don't know exactly how to get only that part of the variable $dir_path. Remember the
> filename is not a constant. It will change every time the script runs depending on what
> data needs to be extracted.
> Waiting for your reply,
> thanks in advance,
> Looking for local information? Find it on Yahoo! Local http://in.local.yahoo.com/
> [Non-text portions of this message have been removed]