Loading ...
Sorry, an error occurred while loading the content.

Re: Regular expressions help

Expand Messages
  • Vivek Kumar
    Hi Nikhil, hope this will resolve your problem $dir_path = /abc/def/ghi/pp123456.2.3.4.jk.xyz ; $filename = ($dir_path =~ /(.*) /(.*) /(.*) /(.*)/); $filename
    Message 1 of 4 , Aug 1, 2009
      Hi Nikhil,

      hope this will resolve your problem

      $dir_path = "/abc/def/ghi/pp123456.2.3.4.jk.xyz";
      $filename = ($dir_path =~ /(.*)\/(.*)\/(.*)\/(.*)/);
      $filename = $4;
      $fileDirectory = $1."/"."$2"."/".$3;
      print $filename;
      print "\n";
      print $fileDirectory;

      The output of the result will be :


      Vivek Kumar

      --- In perl-beginner@yahoogroups.com, 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/pp123456.2.3.4.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:
      > pp123456.2.3.4.jk.xyz
      > 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,
      > Nik
      > Looking for local information? Find it on Yahoo! Local http://in.local.yahoo.com/
      > [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.