Re: Help needed for perl rookie

From: GRLCOPM (grlcopm_at_pacbell.net)
Date: 12/28/04


Date: Tue, 28 Dec 2004 16:31:37 GMT


> From: Bob Walton <see_sig@invalid>
> Organization: Newsfeed.com http://www.newsfeeds.com 100,000+ UNCENSORED
> Newsgroups.
> Newsgroups: comp.lang.perl.misc
> Date: Mon, 27 Dec 2004 22:34:20 -0500
> Subject: Re: Help needed for perl rookie
>
> GRLCOPM wrote:
>
>> I am new to perl, but so far have had decent success in writing/modifying
>> code to do what I want to do. However I am stuck trying to modify the
>> following code. I am sure the solution is quite simple, but I can't
>> completely figure out what this piece of code does. I think it is just
>> matching up a data pattern but this is an area I am unfamiliar with.
>>
>> All I want to do is change the format of the data file from example #1 to
>> example #2 and need this section of code to work with the new format. I
>> would be grateful for any help provided in understanding what this piece of
>> code does and suggestions on the modification needed.
>>
>> If more information or a larger chunk of the code is needed please let me
>> know and I will provide.
>>
>> EXAMPLE #1 - Current format of data file:
>> 0000000050 20041227 0000000003 'my-page.shtml'
>> 0000000054 20041227 0000000004 'another-page.shtml'
>> 0000000020 20041227 0000000003 'yet-another-page.shtml'
>>
>> EXAMPLE #2 - New format of data file:
>> 0000000050|20041227|0000000003|my-page.shtml
>> 0000000054|20041227|0000000004|another-page.shtml
>> 0000000020|20041227|0000000003|yet-another-page.shtml
>
> Your example #2 is in "pipe-delimited" form -- the best way to
> split it apart is with the split() function, as in:
>
> ($acc,$day,$dayacc,$uri)=split /\|/,$line;
>
>
>> if (($acc,$day,$dayacc,$uri) = ($line =~ /^(\d+) (\d+) (\d+) '(\S+)'$/)) {
>
>
> --
> Bob Walton
> Email: http://bwalton.com/cgi-bin/emailbob.pl

Thanks Bob,

I am familiar with the split function and have been looking for a solution
that utilizes it, but the line you provided does not seem to work as a
replacement for the line I included. I have been looking through
documentation including the references you provided, but I am still having a
hard time with this. I guess what I am looking for is someone to break down
what is happening in this line so that I can modify it to work as I need it
to. Here is the section of code in question.

&LockOpen (COUNT,"$AccessFile");
$location = tell COUNT;
while ($line = <COUNT>) {
  if (($acc,$day,$dayacc,$uri) = ($line =~ /^(\d+) (\d+) (\d+) '(\S+)'$/)) {
      if ($uri eq $doc_uri) {
          last;
      }
  }
  last if ($uri eq $doc_uri);
  $location = tell COUNT;
  $acc = 0;
  $dayacc = 0;
}

And here is the specific line:

if (($acc,$day,$dayacc,$uri) = ($line =~ /^(\d+) (\d+) (\d+) '(\S+)'$/)) {

It reads the data file that is in this format:

EXAMPLE #1 - Current format of data file:
0000000050 20041227 0000000003 'my-page.shtml'
0000000054 20041227 0000000004 'another-page.shtml'
0000000020 20041227 0000000003 'yet-another-page.shtml'

I need it to perform the same function on a data file in this format:

EXAMPLE #2 - New format of data file:
0000000050|20041227|0000000003|my-page.shtml
0000000054|20041227|0000000004|another-page.shtml
0000000020|20041227|0000000003|yet-another-page.shtml

Based on the way this program works, my guess is that $uri is being compared
with the data inside the quotes '(\S+)' taken from the current line of the
data file. Right?

I appreciate your help and any further advice you or anyone else can offer.

- Patrick



Relevant Pages

  • Re: Using dates during mail merge
    ... The other thing that might be causing problems here is that, regardless of how the DATE field nested in the ASK field is formatted, the user will need to enter the date in the format set up in their regional options (or any other format where the month and day are not ambiguous. ... I was however remiss in not changing the field name from that in my data file as this added some unwelcome confusion:( ... You included 'MyDate' and 'Date2' in your ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Max. Size Outlook file / split into various accounts?
    ... Properties of Persoanal Folders, in the General tab, click Advanced, look ... Anyhow if its a clean install of Outlook 2003 with a new data file +20gb ... unicode format and hence I should be safe up to 20GB? ...
    (microsoft.public.outlook.general)
  • Re: 03 versus 97/2002 version
    ... The new format is not backwards compatible so proceed at your own risk. ... File->new-outlook data file. ... dragging to the new calendar FOLDER works best. ...
    (microsoft.public.outlook)
  • Re: Using dates during mail merge
    ... If you have some other format but January eg january or JANUARY you will ... Word MVP web site http://word.mvps.org ... that in my data file as this added some unwelcome confusion:(-- ... You included 'MyDate' and 'Date2' in your ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Help needed for perl rookie
    ... > Newsgroups: comp.lang.perl.misc ... that is how I have changed the format of the data file. ... >> the replacement would be? ...
    (comp.lang.perl.misc)