[29173] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 417 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 8 16:10:11 2007

Date: Tue, 8 May 2007 13:09:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 8 May 2007     Volume: 11 Number: 417

Today's topics:
    Re: Action before clicking a link <no@email.com>
        Click link to go to routine <sykigh@trist.com>
    Re: Click link to go to routine <joe@inwap.com>
    Re: Click link to go to routine <xicheng@gmail.com>
    Re: Link Matching <hjp-usenet2@hjp.at>
    Re: Link Matching <hjp-usenet2@hjp.at>
    Re: Multiple copy and paste thing in Perl <hjp-usenet2@hjp.at>
        parsing a variable length record from a mixed format fi chadmay@hotmail.com
    Re: parsing a variable length record from a mixed forma (Greg Bacon)
    Re: parsing a variable length record from a mixed forma chadmay@hotmail.com
    Re: parsing a variable length record from a mixed forma <tuser3@gmail.com>
    Re: parsing a variable length record from a mixed forma <someone@example.com>
    Re: Using an array to search a text file (Greg Bacon)
    Re: Using an array to search a text file <sigzero@gmail.com>
    Re: Using an array to search a text file <mritty@gmail.com>
    Re: Using an array to search a text file <uri@stemsystems.com>
    Re: Using an array to search a text file <mritty@gmail.com>
    Re: Website programming (search + statistics) <ignoramus17686@NOSPAM.17686.invalid>
    Re: Website programming (search + statistics) <xicheng@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 08 May 2007 20:53:50 +0100
From: Brian Wakem <no@email.com>
Subject: Re: Action before clicking a link
Message-Id: <5ac2qeF2m0vgdU1@mid.individual.net>

lg wrote:

> I have the following code (scaled down from complete code):
> 
> 
> [snip]
> print "Press link below to go to next level";
> print '<form action="http://thisandthat.com" method="post">';
> print "</form>";
> [snip]
> 
> When user clicks the link he then goes to the page link point to.
> I would like to save info that the user has clicked the link.
> How do I do that?


Point to a script which redirects after logging.


-- 
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png


------------------------------

Date: Tue, 08 May 2007 18:35:15 GMT
From: "Sykigh A Trist" <sykigh@trist.com>
Subject: Click link to go to routine
Message-Id: <Dp30i.9174$j63.641@newsread2.news.pas.earthlink.net>

I am a complete novice at this. The code below has a link. When it is 
clicked I would like it to go to a routine called "return_this" instead of 
to the website. Can this be done within this code and does anyone mind 
showing me how to do it? Thanks.


  print "<center><a href=\"http://www.scripts.net/\" target=\"_top\">Go 
Back</a>\n";



------------------------------

Date: Tue, 08 May 2007 12:11:01 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Click link to go to routine
Message-Id: <7qydncvH58vbVt3bnZ2dnUVZ_uHinZ2d@comcast.com>

Sykigh A Trist wrote:
> I am a complete novice at this. The code below has a link. When it is 
> clicked I would like it to go to a routine called "return_this" instead 
> of to the website. Can this be done within this code

Can't be done with plain HTML.
It could be done with JavaScript, but not Perl.

You have to understand that if your perl program resides on a server,
then the end user's browser _must_ go to the server to execute your program.
	-Joe


------------------------------

Date: 8 May 2007 13:06:10 -0700
From: Xicheng Jia <xicheng@gmail.com>
Subject: Re: Click link to go to routine
Message-Id: <1178654770.068084.215810@o5g2000hsb.googlegroups.com>

On May 8, 2:35 pm, "Sykigh A Trist" <syk...@trist.com> wrote:
> I am a complete novice at this. The code below has a link. When it is
> clicked I would like it to go to a routine called "return_this" instead of
> to the website. Can this be done within this code and does anyone mind
> showing me how to do it? Thanks.
>
>   print "<center><a href=\"http://www.scripts.net/\" target=\"_top\">Go
> Back</a>\n";

If the routine "return_this" resides in your web server, you can wrap
it into a CGI script or some Perl templating system files, then:

   print '<center><a href="/path/to/return_this.pl?name=skyhigh"
target="_top">Go Back</a>\n';

Just add any necessary argument into the query string of that linked
script..

Regards,
Xicheng



------------------------------

Date: Tue, 8 May 2007 18:23:58 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Link Matching
Message-Id: <slrnf4190u.vtt.hjp-usenet2@zeno.hjp.at>

On 2007-05-08 01:21, Tad McClellan <tadmc@augustmail.com> wrote:
> Xicheng Jia <xicheng@gmail.com> wrote:
>> On May 7, 8:10 pm, Tad McClellan <t...@augustmail.com> wrote:
>>> $html = <<END_HTML;
>>>     <p>
>>>        If b<a then href="bbb"
        </p>
>>
>> That is ill-formated html 
>
>
> It is perfectly valid HTML.

I don't think so. "<a " looks like the start of an "a" tag, but the rest
of it isn't well-formed ("then" is not an attribute of "a", and an
unquoted "</" is syntactically wrong. I don't have the syntax rules for
SGML at hand but i doubt that they require backtracking to the "<" and
reinterpret it as a literal "<" instead of the start of a tag. 

Adding two spaces makes it valid:

      If b < a then href="bbb"

	hp


-- 
   _  | Peter J. Holzer    | I know I'd be respectful of a pirate 
|_|_) | Sysadmin WSR       | with an emu on his shoulder.
| |   | hjp@hjp.at         |
__/   | http://www.hjp.at/ |	-- Sam in "Freefall"


------------------------------

Date: Tue, 8 May 2007 18:39:50 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Link Matching
Message-Id: <slrnf419um.9f.hjp-usenet2@zeno.hjp.at>

On 2007-05-08 01:21, Tad McClellan <tadmc@augustmail.com> wrote:
> Xicheng Jia <xicheng@gmail.com> wrote:
>> On May 7, 8:10 pm, Tad McClellan <t...@augustmail.com> wrote:
>>> $html = <<END_HTML;
>>>     <p>
>>>        If b<a then href="bbb"
        </p>
>>
>> That is ill-formated html 
>
>
> It is perfectly valid HTML.

I don't think so. "<a " looks like the start of an "a" tag, but the rest
of it isn't well-formed ("then" is not an attribute of "a", and an
unquoted "</" is syntactically wrong). I don't have the syntax rules for
SGML at hand but i doubt that they require backtracking to the "<" and
reinterpret it as a literal "<" instead of the start of a tag. 

Adding two spaces makes it valid:

      If b < a then href="bbb"

	hp


-- 
   _  | Peter J. Holzer    | I know I'd be respectful of a pirate 
|_|_) | Sysadmin WSR       | with an emu on his shoulder.
| |   | hjp@hjp.at         |
__/   | http://www.hjp.at/ |	-- Sam in "Freefall"


------------------------------

Date: Tue, 8 May 2007 18:32:01 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Multiple copy and paste thing in Perl
Message-Id: <slrnf419g1.vtt.hjp-usenet2@zeno.hjp.at>

On 2007-05-07 14:40, Petr Vileta <stoupa@practisoft.cz> wrote:
> "TefJlives" <gmarkowsky@gmail.com> píse v diskusním príspevku 
> news:1178502077.800790.92800@y80g2000hsf.googlegroups.com...
> As I know to isolate RightControl key is not possible because it is not 
> handled by hardware. You can detect right or left Shift or Alt but not 
> Control.

Sure you can. X11 on Linux reports a keycode of 37 for the left control
key and 109 for the right control key. (I think these are also the scan
codes sent by the hardware, but I may be misremembering things - it's
been about 15 years that I wrote a keyboard driver).

	hp


-- 
   _  | Peter J. Holzer    | I know I'd be respectful of a pirate 
|_|_) | Sysadmin WSR       | with an emu on his shoulder.
| |   | hjp@hjp.at         |
__/   | http://www.hjp.at/ |	-- Sam in "Freefall"


------------------------------

Date: 8 May 2007 08:41:30 -0700
From: chadmay@hotmail.com
Subject: parsing a variable length record from a mixed format file
Message-Id: <1178638890.499518.294170@q75g2000hsh.googlegroups.com>

I have a flat file that had a mix of fixed length and variable length
records. I am parsing through each record and determining if each
field is accurate compared to the document. Dealing with the fixed
length records was easy, but I'm having difficulting with the variable
length records. Here is a snippet of my code and record 3
(ACCT_CLUS_NM) is a variable length record. Since the record in my
test file isn't 45 chars, my output file is incorrect. Since I know
that the largest that record 3 will be is 45 chars, how do I code for
it??

#!/usr/bin/perl

$loop=57;
$ifname=$ARGV[0];
$ofname=$ARGV[1];

if("${ifname}" eq "" | "${ofname}" eq "")
{
  print "\nUsage: $0 input_file output_file\n";
  exit;
}
if(!-f "$ifname" | !-r "$ifname")
{
  print "$ifname doesn't exist or you do not have permission to read
it.\n";
  exit 1;
}
if(-f "$ofname")
{
  print "$ofname already exists.\n";
  exit 1;
}

open(BATCHF, "$ifname") or die "Open failed: $!\n";
open(FBATCHF, ">> $ofname") or die "Open failed: $!\n";

while (<BATCHF>)
{
$RECIN=$_;
$fpos=0;
for ($cnt=1;$cnt<=$loop;$cnt++)
{
if($cnt==1){$reclength=4;$field="ACCOUNT_TYPE"};
if($cnt==2){$reclength=1;$field="TAB"};
if($cnt==3){$reclength=45;$field="ACCT_CLUS_NM"};
if($cnt==4){$reclength=1;$field="TAB"};
if($cnt==5){$reclength=9;$field="ACCT_NBR"};
if($cnt==6){$reclength=1;$field="TAB"};
if($cnt==7){$reclength=3;$field="CORP_ENT_CD"};
if($cnt==8){$reclength=1;$field="TAB"};
if($cnt==9){$reclength=9;$field="CUSTOMER_NO"};
if($cnt==10){$reclength=1;$field="TAB"};
if($cnt==11){$reclength=20;$field="D_BEN_AGMT_DESC"};
if($cnt==12){$reclength=1;$field="TAB"};
if($cnt==13){$reclength=10;$field="D_BEN_AGMT_EFF_DT"};
if($cnt==14){$reclength=1;$field="TAB"};
if($cnt==15){$reclength=8;$field="D_FUND_TYP_CD"};
if($cnt==16){$reclength=1;$field="TAB"};
if($cnt==17){$reclength=6;$field="D_PROD_TYP_CD"};
if($cnt==18){$reclength=1;$field="TAB"};
if($cnt==19){$reclength=8;$field="FOLDED_FUNDING_TYPE"};
if($cnt==20){$reclength=1;$field="TAB"};
if($cnt==21){$reclength=40;$field="GROUP_NAME"};
if($cnt==22){$reclength=1;$field="TAB"};
if($cnt==23){$reclength=9;$field="GROUP_NO"};
if($cnt==24){$reclength=1;$field="TAB"};
if($cnt==25){$reclength=2;$field="GRP_CAN_CD"};
if($cnt==26){$reclength=1;$field="TAB"};
if($cnt==27){$reclength=10;$field="GRP_CAN_DT"};
if($cnt==28){$reclength=1;$field="TAB"};
if($cnt==29){$reclength=10;$field="GS_ORIGL_EFF_DT"};
if($cnt==30){$reclength=1;$field="TAB"};
if($cnt==31){$reclength=20;$field="H_BEN_AGMT_DESC"};
if($cnt==32){$reclength=1;$field="TAB"};
if($cnt==33){$reclength=10;$field="H_BEN_AGMT_EFF_DT"};
if($cnt==34){$reclength=1;$field="TAB"};
if($cnt==35){$reclength=8;$field="H_FUND_TYP_CD"};
if($cnt==36){$reclength=1;$field="TAB"};
if($cnt==37){$reclength=6;$field="H_PROD_TYP_CD"};
if($cnt==38){$reclength=1;$field="TAB"};
if($cnt==39){$reclength=10;$field="LOAD_DT"};
if($cnt==40){$reclength=1;$field="TAB"};
if($cnt==41){$reclength=10;$field="LST_UPDT_DT"};
if($cnt==42){$reclength=1;$field="TAB"};
if($cnt==43){$reclength=4;$field="MKT_SEG_CD"};
if($cnt==44){$reclength=1;$field="TAB"};
if($cnt==45){$reclength=45;$field="NAME"};
if($cnt==46){$reclength=1;$field="TAB"};
if($cnt==47){$reclength=10;$field="ROW_EFFECTIVE_DT"};
if($cnt==48){$reclength=1;$field="TAB"};
if($cnt==49){$reclength=10;$field="ROW_END_DT"};
if($cnt==50){$reclength=1;$field="TAB"};
if($cnt==51){$reclength=5;$field="SECT_NBR"};
if($cnt==52){$reclength=1;$field="TAB"};
if($cnt==53){$reclength=40;$field="SECT_NM"};
if($cnt==54){$reclength=1;$field="TAB"};
if($cnt==55){$reclength=4;$field="SIC_CD"};
if($cnt==56){$reclength=1;$field="TAB"};
if($cnt==57){$reclength=10;$field="TIER_TYPE"};
chomp($RECIN);
  $RECOUT=substr($RECIN,$fpos,$reclength);
  $fpos=$reclength + $fpos;
  print FBATCHF "$field $reclength |$RECOUT|\n";
}
print FBATCHF "------------------------------------------------\n";
}
close BATCHF;
close FBATCHF;



------------------------------

Date: Tue, 08 May 2007 16:10:45 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: parsing a variable length record from a mixed format file
Message-Id: <13418859njue7ef@corp.supernews.com>

In article <1178638890.499518.294170@q75g2000hsh.googlegroups.com>,
     <chadmay@hotmail.com> wrote:

: I have a flat file that had a mix of fixed length and variable length
: records. I am parsing through each record and determining if each
: field is accurate compared to the document. Dealing with the fixed
: length records was easy, but I'm having difficulting with the variable
: length records. Here is a snippet of my code and record 3
: (ACCT_CLUS_NM) is a variable length record. Since the record in my
: test file isn't 45 chars, my output file is incorrect. Since I know
: that the largest that record 3 will be is 45 chars, how do I code for
: it??

Are the fields you tagged with "TAB" literal TAB characters? If so,
extracting the fields is easy:

  @fields = split /\t/, $RECIN;

Hope this helps,
Greg
-- 
Every election is a sort of advance auction sale of stolen goods.
    -- H. L. Mencken


------------------------------

Date: 8 May 2007 10:36:23 -0700
From: chadmay@hotmail.com
Subject: Re: parsing a variable length record from a mixed format file
Message-Id: <1178645783.296178.81720@e51g2000hsg.googlegroups.com>

On May 8, 11:10 am, gba...@hiwaay.net (Greg Bacon) wrote:
> In article <1178638890.499518.294...@q75g2000hsh.googlegroups.com>,
>      <chad...@hotmail.com> wrote:
>
> : I have a flat file that had a mix of fixed length and variable length
> : records. I am parsing through each record and determining if each
> : field is accurate compared to the document. Dealing with the fixed
> : length records was easy, but I'm having difficulting with the variable
> : length records. Here is a snippet of my code and record 3
> : (ACCT_CLUS_NM) is a variable length record. Since the record in my
> : test file isn't 45 chars, my output file is incorrect. Since I know
> : that the largest that record 3 will be is 45 chars, how do I code for
> : it??
>
> Are the fields you tagged with "TAB" literal TAB characters? If so,
> extracting the fields is easy:
>
>   @fields = split /\t/, $RECIN;
>
> Hope this helps,
> Greg
> --
> Every election is a sort of advance auction sale of stolen goods.
>     -- H. L. Mencken

You are correct, those are literal TABS that I've specificly listed in
the record layout. Since I'm somewhat of a PERL newbie, I want to make
sure I'm not missing anything. Where would I insert the line you
proposed and what other changes to my current code, do I need to make?

Thanks again,
Chad



------------------------------

Date: 8 May 2007 12:36:42 -0700
From: tuser <tuser3@gmail.com>
Subject: Re: parsing a variable length record from a mixed format file
Message-Id: <1178653002.373576.192310@l77g2000hsb.googlegroups.com>

On May 8, 5:41 pm, chad...@hotmail.com wrote:
> I have a flat file that had a mix of fixed length and variable length
> records. I am parsing through each record and determining if each
> field is accurate compared to the document. Dealing with the fixed
> length records was easy, but I'm having difficulting with the variable
> length records. Here is a snippet of my code and record 3
> (ACCT_CLUS_NM) is a variable length record. Since the record in my
> test file isn't 45 chars, my output file is incorrect. Since I know
> that the largest that record 3 will be is 45 chars, how do I code for
> it??

I am not sure if I understand your question, but I suggest the
following changes to your program:

> #!/usr/bin/perl

use strict;
use warnings;

> $loop=57;
> $ifname=$ARGV[0];
> $ofname=$ARGV[1];

my $loop = 57;
my $ifname = $ARGV[0];
my $ofname = $ARGV[1];

> if("${ifname}" eq "" | "${ofname}" eq "")
if ($ifname eq "" or $ofname eq "")

no need for curly braces here and no need to quote $ifname or $ofname,
see perlfaq4 (What's wrong with always quoting "$vars" ?).

use "or" instead of "|", see perldoc perlop ("Bitwise Or and Exclusive
Or" and "C-style Logical Or").

> {
>   print "\nUsage: $0 input_file output_file\n";
>   exit;}
>
> if(!-f "$ifname" | !-r "$ifname")

if (!-f $ifname or !-r "$ifname")

no curlies, that's good, but again, "or" instead of "|" and no need to
quote $ifname.

> {
>   print "$ifname doesn't exist or you do not have permission to read
> it.\n";
>   exit 1;}
>
> if(-f "$ofname")

if (-f $ofname)

> {
>   print "$ofname already exists.\n";
>   exit 1;
>
> }
>
> open(BATCHF, "$ifname") or die "Open failed: $!\n";
> open(FBATCHF, ">> $ofname") or die "Open failed: $!\n";

open my $BATCHF, '<', $ifname or die "Open < $ifname failed: $!\n";
open my $FBATCHF, '>>', $ofname or die "Open >> $ofname failed: $!\n";

> while (<BATCHF>)

while (<$BATCHF>)

[ ...snip... ]

> for ($cnt=1;$cnt<=$loop;$cnt++)

for my $cnt (1..$loop)

[ ...snip... ]

>   print FBATCHF "$field $reclength |$RECOUT|\n";

print {$FBATCHF} "$field $reclength |$RECOUT|\n";

> close BATCHF;
> close FBATCHF;

close $BATCHF;
close $FBATCHF;

--
Klaus



------------------------------

Date: Tue, 08 May 2007 19:43:56 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: parsing a variable length record from a mixed format file
Message-Id: <0q40i.13918$au6.8619@edtnps90>

chadmay@hotmail.com wrote:
> I have a flat file that had a mix of fixed length and variable length
> records. I am parsing through each record and determining if each
> field is accurate compared to the document. Dealing with the fixed
> length records was easy, but I'm having difficulting with the variable
> length records. Here is a snippet of my code and record 3
> (ACCT_CLUS_NM) is a variable length record. Since the record in my
> test file isn't 45 chars, my output file is incorrect. Since I know
> that the largest that record 3 will be is 45 chars, how do I code for
> it??

It looks like this may be close to what you want:

#!/usr/bin/perl
use warnings;
use strict;

@ARGV == 2 or die "\nUsage: $0 input_file output_file\n";

my ( $ifname, $ofname ) = @ARGV;

my @fields = qw(
    ACCOUNT_TYPE
    ACCT_CLUS_NM
    ACCT_NBR
    CORP_ENT_CD
    CUSTOMER_NO
    D_BEN_AGMT_DESC
    D_BEN_AGMT_EFF_DT
    D_FUND_TYP_CD
    D_PROD_TYP_CD
    FOLDED_FUNDING_TYPE
    GROUP_NAME
    GROUP_NO
    GRP_CAN_CD
    GRP_CAN_DT
    GS_ORIGL_EFF_DT
    H_BEN_AGMT_DESC
    H_BEN_AGMT_EFF_DT
    H_FUND_TYP_CD
    H_PROD_TYP_CD
    LOAD_DT
    LST_UPDT_DT
    MKT_SEG_CD
    NAME
    ROW_EFFECTIVE_DT
    ROW_END_DT
    SECT_NBR
    SECT_NM
    SIC_CD
    TIER_TYPE
    );

open BATCHF,  '<',  $ifname or die "Open '$ifname' failed: $!\n";
open FBATCHF, '>>', $ofname or die "Open '$ofname' failed: $!\n";

while ( my $RECIN = <BATCHF> ) {
    chomp $RECIN;
    @records = split /\t/, $RECIN, -1;
    print FBATCHF map( "$fields[$_] " . length( $records[ $_ ] ) . "
|$records[$_]|\n", 0 .. $#fields ), '-' x 48, "\n";
    }

close BATCHF;
close FBATCHF;









> 
> #!/usr/bin/perl
> 
> $loop=57;
> $ifname=$ARGV[0];
> $ofname=$ARGV[1];
> 
> if("${ifname}" eq "" | "${ofname}" eq "")
> {
>   print "\nUsage: $0 input_file output_file\n";
>   exit;
> }
> if(!-f "$ifname" | !-r "$ifname")
> {
>   print "$ifname doesn't exist or you do not have permission to read
> it.\n";
>   exit 1;
> }
> if(-f "$ofname")
> {
>   print "$ofname already exists.\n";
>   exit 1;
> }
> 
> open(BATCHF, "$ifname") or die "Open failed: $!\n";
> open(FBATCHF, ">> $ofname") or die "Open failed: $!\n";
> 
> while (<BATCHF>)
> {
> $RECIN=$_;
> $fpos=0;
> for ($cnt=1;$cnt<=$loop;$cnt++)
> {
> if($cnt==1){$reclength=4;$field="ACCOUNT_TYPE"};
> if($cnt==2){$reclength=1;$field="TAB"};
> if($cnt==3){$reclength=45;$field="ACCT_CLUS_NM"};
> if($cnt==4){$reclength=1;$field="TAB"};
> if($cnt==5){$reclength=9;$field="ACCT_NBR"};
> if($cnt==6){$reclength=1;$field="TAB"};
> if($cnt==7){$reclength=3;$field="CORP_ENT_CD"};
> if($cnt==8){$reclength=1;$field="TAB"};
> if($cnt==9){$reclength=9;$field="CUSTOMER_NO"};
> if($cnt==10){$reclength=1;$field="TAB"};
> if($cnt==11){$reclength=20;$field="D_BEN_AGMT_DESC"};
> if($cnt==12){$reclength=1;$field="TAB"};
> if($cnt==13){$reclength=10;$field="D_BEN_AGMT_EFF_DT"};
> if($cnt==14){$reclength=1;$field="TAB"};
> if($cnt==15){$reclength=8;$field="D_FUND_TYP_CD"};
> if($cnt==16){$reclength=1;$field="TAB"};
> if($cnt==17){$reclength=6;$field="D_PROD_TYP_CD"};
> if($cnt==18){$reclength=1;$field="TAB"};
> if($cnt==19){$reclength=8;$field="FOLDED_FUNDING_TYPE"};
> if($cnt==20){$reclength=1;$field="TAB"};
> if($cnt==21){$reclength=40;$field="GROUP_NAME"};
> if($cnt==22){$reclength=1;$field="TAB"};
> if($cnt==23){$reclength=9;$field="GROUP_NO"};
> if($cnt==24){$reclength=1;$field="TAB"};
> if($cnt==25){$reclength=2;$field="GRP_CAN_CD"};
> if($cnt==26){$reclength=1;$field="TAB"};
> if($cnt==27){$reclength=10;$field="GRP_CAN_DT"};
> if($cnt==28){$reclength=1;$field="TAB"};
> if($cnt==29){$reclength=10;$field="GS_ORIGL_EFF_DT"};
> if($cnt==30){$reclength=1;$field="TAB"};
> if($cnt==31){$reclength=20;$field="H_BEN_AGMT_DESC"};
> if($cnt==32){$reclength=1;$field="TAB"};
> if($cnt==33){$reclength=10;$field="H_BEN_AGMT_EFF_DT"};
> if($cnt==34){$reclength=1;$field="TAB"};
> if($cnt==35){$reclength=8;$field="H_FUND_TYP_CD"};
> if($cnt==36){$reclength=1;$field="TAB"};
> if($cnt==37){$reclength=6;$field="H_PROD_TYP_CD"};
> if($cnt==38){$reclength=1;$field="TAB"};
> if($cnt==39){$reclength=10;$field="LOAD_DT"};
> if($cnt==40){$reclength=1;$field="TAB"};
> if($cnt==41){$reclength=10;$field="LST_UPDT_DT"};
> if($cnt==42){$reclength=1;$field="TAB"};
> if($cnt==43){$reclength=4;$field="MKT_SEG_CD"};
> if($cnt==44){$reclength=1;$field="TAB"};
> if($cnt==45){$reclength=45;$field="NAME"};
> if($cnt==46){$reclength=1;$field="TAB"};
> if($cnt==47){$reclength=10;$field="ROW_EFFECTIVE_DT"};
> if($cnt==48){$reclength=1;$field="TAB"};
> if($cnt==49){$reclength=10;$field="ROW_END_DT"};
> if($cnt==50){$reclength=1;$field="TAB"};
> if($cnt==51){$reclength=5;$field="SECT_NBR"};
> if($cnt==52){$reclength=1;$field="TAB"};
> if($cnt==53){$reclength=40;$field="SECT_NM"};
> if($cnt==54){$reclength=1;$field="TAB"};
> if($cnt==55){$reclength=4;$field="SIC_CD"};
> if($cnt==56){$reclength=1;$field="TAB"};
> if($cnt==57){$reclength=10;$field="TIER_TYPE"};
> chomp($RECIN);
>   $RECOUT=substr($RECIN,$fpos,$reclength);
>   $fpos=$reclength + $fpos;
>   print FBATCHF "$field $reclength |$RECOUT|\n";
> }
> print FBATCHF "------------------------------------------------\n";
> }
> close BATCHF;
> close FBATCHF;
> 







John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


------------------------------

Date: Tue, 08 May 2007 16:02:24 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Using an array to search a text file
Message-Id: <13417oggdbijo0d@corp.supernews.com>

In article <1178636160.359445.14080@o5g2000hsb.googlegroups.com>,
    Robert Hicks  <sigzero@gmail.com> wrote:

: On May 8, 10:26 am, Paul Lalli <mri...@gmail.com> wrote:

: > Yes.  the readline operator will return undef once the file has been
: > exhausted.
: >
: > perldoc -f seek
:
: I just did that after I asked my question.  : )
: 
: The loop is working now but I get the following error as well:
: 
: "Use of uninitialized value in regexp compilation at"
: 
: That happens at the regex "if ( $line =~ /$id/ ) {"

That seems to be due to the following line:

: seek($AFILE, 0, 1) unless $prime_id = undef;

Perl borrows C's = and == operators and also their easy slipups.
Your code sets $prime_id to the undefined value, probably not
what you intended.

In general, use the defined operator to test whether a value is
defined. In your case, $prime_id should always be defined, so you
can drop the test.

Even better, you can improve your algorithm. You're making a
separate pass through AFILE for each id, but you can do it in one:

    $ cat mkifile 
    #! /usr/bin/perl -l

    use warnings;
    use strict;

    my($min,$max) = (10,30);
    my @fill = ('A' .. 'Z', 'a' .. 'z', 0 .. 9, '-', '/');

    for (1 .. 10) {
      print chr(ord('A') + rand 26),
            sprintf("%04d", rand 10_000),
            map $fill[rand @fill], 1 .. $min + rand($max - $min + 1);
    }

    $ ./mkifile | tee ifile
    D3438GLB1zolY/HFJ
    R1955G4Uv4PNIPr//A/azJPw
    P18551C7ApRSsXO
    B2271/b0FU36keL6T9y64oJo-hTT6A
    F3585SHedJHMVEZN0L6enB0KfpBCQG
    A4526KUJJFa4eTeoHIKyS067qZ7q3v
    H0098x4sfeiEDJqI7fFIjvb
    E7946A6MzMpy9MlSsYauZ-J2l-9W0HnhsG
    F32758YHVeRwd7mnWT
    E7854hzhveSZAvJR

    $ cat mkafile 
    #! /usr/bin/perl -l

    use warnings;
    use strict;

    @ARGV = ("ifile") unless @ARGV;

    my $count;

    while (<>) {
      my $id = substr $_, 0, 5;

      print join " " =>
            "A-preparse ",
            "/msg_data/msg_dir120/${id}EZ20070430.0018: ",
            "GOOD MESSAGE DETECTED";

      print "--- SHOULD NOT MATCH ", ++$count;
    }

    $ ./mkafile | tee afile
    A-preparse  /msg_data/msg_dir120/D3438EZ20070430.0018: [...]
    --- SHOULD NOT MATCH 1
    A-preparse  /msg_data/msg_dir120/R1955EZ20070430.0018: [...]
    --- SHOULD NOT MATCH 2
    A-preparse  /msg_data/msg_dir120/P1855EZ20070430.0018: [...]
    --- SHOULD NOT MATCH 3
    A-preparse  /msg_data/msg_dir120/B2271EZ20070430.0018: [...]
    --- SHOULD NOT MATCH 4
    A-preparse  /msg_data/msg_dir120/F3585EZ20070430.0018: [...]
    --- SHOULD NOT MATCH 5
    A-preparse  /msg_data/msg_dir120/A4526EZ20070430.0018: [...]
    --- SHOULD NOT MATCH 6
    A-preparse  /msg_data/msg_dir120/H0098EZ20070430.0018: [...]
    --- SHOULD NOT MATCH 7
    A-preparse  /msg_data/msg_dir120/E7946EZ20070430.0018: [...]
    --- SHOULD NOT MATCH 8
    A-preparse  /msg_data/msg_dir120/F3275EZ20070430.0018: [...]
    --- SHOULD NOT MATCH 9
    A-preparse  /msg_data/msg_dir120/E7854EZ20070430.0018: [...]
    --- SHOULD NOT MATCH 10

    $ cat try
    #! /usr/bin/perl

    use strict;
    use warnings;

    sub id_matcher {
      open my $fh, "<", "ifile" or die "$0: open";

      my $ids = join "|" =>
                map quotemeta(substr $_, 0, 5),
                <$fh>;

      qr/$ids/;
    }

    my $idpattern = id_matcher;

    @ARGV = ("afile") unless @ARGV;

    while (<>) {
      print if /$idpattern/;
    }

    $ ./try
    A-preparse  /msg_data/msg_dir120/D3438EZ20070430.0018: [...]
    A-preparse  /msg_data/msg_dir120/R1955EZ20070430.0018: [...]
    A-preparse  /msg_data/msg_dir120/P1855EZ20070430.0018: [...]
    A-preparse  /msg_data/msg_dir120/B2271EZ20070430.0018: [...]
    A-preparse  /msg_data/msg_dir120/F3585EZ20070430.0018: [...]
    A-preparse  /msg_data/msg_dir120/A4526EZ20070430.0018: [...]
    A-preparse  /msg_data/msg_dir120/H0098EZ20070430.0018: [...]
    A-preparse  /msg_data/msg_dir120/E7946EZ20070430.0018: [...]
    A-preparse  /msg_data/msg_dir120/F3275EZ20070430.0018: [...]
    A-preparse  /msg_data/msg_dir120/E7854EZ20070430.0018: [...]

Hope this helps,
Greg
-- 
The urge to save humanity is almost always a false front for the urge to rule. 
    -- H.L. Mencken


------------------------------

Date: 8 May 2007 10:00:48 -0700
From: Robert Hicks <sigzero@gmail.com>
Subject: Re: Using an array to search a text file
Message-Id: <1178643648.388202.252460@e51g2000hsg.googlegroups.com>

Greg,

Mine doesn't complete using the second version. Is anything loading
into memory? The log file the while statement would be reading is
pretty big.

Bob



------------------------------

Date: 8 May 2007 10:38:05 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Using an array to search a text file
Message-Id: <1178645885.163521.209520@u30g2000hsc.googlegroups.com>

On May 8, 10:56 am, Robert Hicks <sigz...@gmail.com> wrote:

> The loop is working now but I get the following error as well:
>
> "Use of uninitialized value in regexp compilation at"
>
> That happens at the regex "if ( $line =~ /$id/ ) {"

There is no such line in the below code.  Presumably you mean
$prime_id there.

>
> foreach my $prime_id ( @id_hits ) {
>     while ( my $line = <$AFILE> ) {
>         chomp $line;
>         if ( $line =~ /$prime_id/ ) {

if you're not 100% positive that $prime_id will never contain
characters that are special to regular expressions -- * + | ( ) [ { ?
^ $ \ . -- then you should surround it with \Q...\E, like so:
if ($line =~ /\Q$prime_id\E/) {

Adding those will almost never hurt, and will usually help.

>             print "$line\n";

chomping $line only to then print $line with a newline appended seems
counterproductive.

>             next;

a 'next' as the last line of a loop is a no-op.  I have no idea why
you think it's necessary here.

>         }
>         seek($AFILE, 0, 1) unless $prime_id = undef;
>     }

You have a few errors here.

1) You're not actually rewinding the file. Setting WHENCE to 1 makes
it move POSITION bytes from where it currenly is.  WHENCE should be 0.

2) You're checking to see if $AFILE needs to be rewound after each
iteration of the loop.  Why?  Just rewind it when the loop ends -
because that's when you know the file has been exhausted.

3) Logic error - you're trying to rewind whenever $prime is undef.
That's never going to be true (or at least it wouldn't be if not for
your fourth error, see below).   I'm guessing you meant that check to
be "don't rewind if this is the first iteration", but the $prime_id
variable has nothing to do with whether or not the file has been
exhausted and needs to be rewound.

4) You're meaning to check to see if $prime_id is undefined, but
instead you're actually undefining $prime_id (which is what causes the
warning you saw in the next and all subsequent iteartions).
Presumably you meant to use == rather than = but that's not right
either.  == compares two values as numbers, meaning that it thinks
undef and 0 are one and the same.  You would need to use the defined()
function, like:
seek($AFILE, 0, 0) if defined $prime_id


Your code should be rewritten like so:

foreach my $prime_id ( @id_hits ) {
    while ( my $line = <$AFILE> ) {
        print $line if $line =~ /$prime_id/ ;
    }
   seek($AFILE, 0, 0); #rewind file when exhausted
}


Hope this helps,
Paul Lalli



------------------------------

Date: Tue, 08 May 2007 15:52:37 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Using an array to search a text file
Message-Id: <x7lkfzw0sa.fsf@mail.sysarch.com>

>>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:

  PL> foreach my $prime_id ( @id_hits ) {
  PL>     while ( my $line = <$AFILE> ) {
  PL>         print $line if $line =~ /$prime_id/ ;
  PL>     }
  PL>    seek($AFILE, 0, 0); #rewind file when exhausted
  PL> }

i don't know why no one has told you to invert the order of the loops
and scan the file once and the ids inside that. no seek is needed and it
will be much faster as the file is read in only one time.

while ( my $line = <$AFILE> ) {
	foreach my $prime_id ( @id_hits ) {
        	print $line if $line =~ /$prime_id/ ;
	}
}

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: 8 May 2007 13:01:54 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Using an array to search a text file
Message-Id: <1178654514.252552.254360@l77g2000hsb.googlegroups.com>

On May 8, 3:52 pm, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "PL" == Paul Lalli <mri...@gmail.com> writes:
>
>   PL> foreach my $prime_id ( @id_hits ) {
>   PL>     while ( my $line = <$AFILE> ) {
>   PL>         print $line if $line =~ /$prime_id/ ;
>   PL>     }
>   PL>    seek($AFILE, 0, 0); #rewind file when exhausted
>   PL> }
>
> i don't know why no one has told you to invert the order of the loops
> and scan the file once and the ids inside that. no seek is needed and it
> will be much faster as the file is read in only one time.
>
> while ( my $line = <$AFILE> ) {
>         foreach my $prime_id ( @id_hits ) {
>                 print $line if $line =~ /$prime_id/ ;
>         }
>
> }

Probably because that would rather drastically alter the order of the
output.... I'm making the assumption that the OP knows in what order
he wants the output.  That's every line that contains the first
$prime_id, then every line that contains the second $prime_id, etc.
You've reversed that to the first line once for each $prime_id it
contains, then the second line once for each $prime_id it contains,
etc.

Paul Lalli



------------------------------

Date: Tue, 08 May 2007 11:23:56 -0500
From: Ignoramus17686 <ignoramus17686@NOSPAM.17686.invalid>
Subject: Re: Website programming (search + statistics)
Message-Id: <cqqdnQ2WqKiBOd3bnZ2dnUVZ_tPinZ2d@giganews.com>

On 7 May 2007 11:04:37 -0700, Xicheng Jia <xicheng@gmail.com> wrote:
> On May 6, 8:49 pm, "Ken Soon" <c...@xilinx.com> wrote:
>> Hi,
>>
>> I have a trying out a website to have this function. This function will
>> allow webusers to search for something in the database of my website and
>> then later display the related information. Plus, there is also some
>> questions for the users to answer for statistics purposes, such as
>> age,monthly income, etc... This is to enable me and probably the users to
>> know what kind of information is searched by what kind of people.
>>
>> I have done quite some perl programming but I have not use perl programming
>> for database and webprogramming. How do I go about doing this?
>> Can anyone help please?
>>
>> Ken
>
> CGI is kind of old tech in the current web development. embedding your
> Perl code directly into the HTML might make your life much easier. one
> of such Perl modules is HTML::Mason, you can check its website and on-
> line free book.
>
>   http://masonhq.com/
>   http://www.masonbook.com/book/
>
> they have very good documentation and site source code..
>
> Good luck,
> Xicheng
>

I used something similar (Embperl), it was a nightmare. Now my entire
pages are perl generated. Lets me separate page layout, placement of
ads etc, from actual content specific to page. 

i


------------------------------

Date: 8 May 2007 11:56:41 -0700
From: Xicheng Jia <xicheng@gmail.com>
Subject: Re: Website programming (search + statistics)
Message-Id: <1178650601.531688.111560@e51g2000hsg.googlegroups.com>

On May 8, 12:23 pm, Ignoramus17686 <ignoramus17...@NOSPAM.
17686.invalid> wrote:
> On 7 May 2007 11:04:37 -0700, Xicheng Jia <xich...@gmail.com> wrote:
>
>
>
>
>
> > On May 6, 8:49 pm, "Ken Soon" <c...@xilinx.com> wrote:
> >> Hi,
>
> >> I have a trying out a website to have this function. This function will
> >> allow webusers to search for something in the database of my website and
> >> then later display the related information. Plus, there is also some
> >> questions for the users to answer for statistics purposes, such as
> >> age,monthly income, etc... This is to enable me and probably the users to
> >> know what kind of information is searched by what kind of people.
>
> >> I have done quite some perl programming but I have not use perl programming
> >> for database and webprogramming. How do I go about doing this?
> >> Can anyone help please?
>
> >> Ken
>
> > CGI is kind of old tech in the current web development. embedding your
> > Perl code directly into the HTML might make your life much easier. one
> > of such Perl modules is HTML::Mason, you can check its website and on-
> > line free book.
>
> >  http://masonhq.com/
> >  http://www.masonbook.com/book/
>
> > they have very good documentation and site source code..
>
> > Good luck,
> > Xicheng
>
> I used something similar (Embperl), it was a nightmare. Now my entire
> pages are perl generated. Lets me separate page layout, placement of
> ads etc, from actual content specific to page.

The page layout things are pretty easy to maintain in HTML::Mason, you
can make it very clean and consistant. If you want a new look for some
sub-directories, just write a new autohandler file at that directory
and set <%flag> element to (inherit => undef) or whatever inheritance
relations. although you also need to make sure they are not making a
(circular | unlimited) loop.

And with HTML::Mason, you dont have to embed every bit of Perl code
into (X?HTML) pages. For pure Perl code, I usually put them into
outside module functions and then call them when necessary and I also
divided components into seperated files(components) according to their
functionalities and glue them by some simple Mason's syntax..

While the best thing of Mason I feel is the inheritance mechnism by
(autohandler|dhandler) which makes the maintanece of website much
easier. other features like (handling different HTTP methods|
interacting with database|et. al) are pretty easy with Mason. But
these features might be more dependent on the mod_perl enviroment. if
you are using it under CGI mode, you might get a completely different
feeling with mine..Just my 2 cents.

Regards,
Xicheng



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 417
**************************************


home help back first fref pref prev next nref lref last post