[18996] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1191 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 25 18:08:01 2001

Date: Mon, 25 Jun 2001 15:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <993506712-v10-i1191@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 25 Jun 2001     Volume: 10 Number: 1191

Today's topics:
        begginers question <ub98aa@brocku.ca>
    Re: begginers question <wolfram.pfeiffer@bigfoot.com>
    Re: begginers question <tony_curtis32@yahoo.com>
    Re: begginers question <miles@explorer.demon.co.uk>
    Re: Checking for duplicates before appending to file (Craig Berry)
    Re: Checking for duplicates before appending to file (Craig Berry)
    Re: Checking for duplicates before appending to file <davsoming@lineone.net>
    Re: Checking for duplicates before appending to file <davsoming@lineone.net>
        counting matches (les ander)
        E-mail help <blnukem@hotmail.com>
    Re: E-mail help <yanoff@yahoo.com>
        Error Message <dbohl@sgi.com>
    Re: finding a file in a directory and reading it (Mark Jason Dominus)
    Re: Getting http file and parsing it. Help please. <patmccourt@eircom.net>
        HELP PLZ; How to remove all the nonprintables character <rig01@yahoo.com>
    Re: HELP PLZ; How to remove all the nonprintables chara (Greg Bacon)
        Help with a regular expression (Asim Beg)
    Re: Help with a regular expression (Mark Jason Dominus)
    Re: Help with a regular expression (Craig Berry)
    Re: Help with a regular expression (Karen J. Cravens)
    Re: How do I cope with pound (currency) sign? (Mark Jason Dominus)
        memory foot print of perl.exe is huge!! <djmarcus@ex-pressnet.com>
    Re: Newbie - Compare text files <jurgenex@hotmail.com>
    Re: Perl *is* strongly typed (was Re: Perl description) <newspost@coppit.org>
    Re: Perl *is* strongly typed (was Re: Perl description) <joe+usenet@sunstarsys.com>
    Re: Perl *is* strongly typed (was Re: Perl description) <buggs-clpm@splashground.de>
        Perl CGI - capturing return values with system calls <miles@explorer.demon.co.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 25 Jun 2001 14:16:47 -0400
From: Umair Tariq Bajwa <ub98aa@brocku.ca>
Subject: begginers question
Message-Id: <3B37800F.4A122E6F@brocku.ca>


--------------FDA92756431554F1387623EA
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Does any know what what i am doing wrong here.

I would like to call the function 4 times and i put it in a for loop. It just print only once.

for (1,2,3,4)
{
   print_form();
}

I even tried this but no success.
for (1..4)
{
   print_form();
}

Thanks for your help.

Umair

--------------FDA92756431554F1387623EA
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>

<pre>Does any know what what i am doing wrong here.</pre>

<pre>I would like to call the function 4 times and i put it in a for loop. It just print only once.</pre>

<pre>for (1,2,3,4)
{
&nbsp;&nbsp; print_form();
}</pre>
I even tried this but no success.
<br>for (1..4)
<br>{
<br>&nbsp;&nbsp; print_form();<br>
}
<p>Thanks for your help.
<p>Umair</html>

--------------FDA92756431554F1387623EA--



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

Date: 25 Jun 2001 18:29:21 GMT
From: Wolfram Pfeiffer <wolfram.pfeiffer@bigfoot.com>
Subject: Re: begginers question
Message-Id: <9h7vu1$p9t$1@news.rz.uni-karlsruhe.de>

Umair Tariq Bajwa <ub98aa@brocku.ca> wrote:
> I would like to call the function 4 times and i put it in a for
> loop. It just print only once.
[snip]
> for (1..4)
> {
>    print_form();
> }

The following snippet:
| #!/usr/bin/perl -w
| use strict;
|
| for (1..4) {
|     print "witless message\n";
| }
produces the desired result for me (four witless messages).

I suggest that you investigate your print_form()-function.

Wolfram


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

Date: 25 Jun 2001 13:39:59 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: begginers question
Message-Id: <87lmmgxv28.fsf@limey.hpcc.uh.edu>

>> On Mon, 25 Jun 2001 14:16:47 -0400,
>> Umair Tariq Bajwa <ub98aa@brocku.ca> said:

> Does any know what what i am doing wrong here.

> I would like to call the function 4 times and i put it
> in a for loop. It just print only once.

> for (1,2,3,4) { print_form(); }
> for (1..4) { print_form(); }

The 2nd method (..) makes more sense as it avoids
enumerating the counter.

for (1,2,3,4) { print "hello\n"; }

does exactly what you're asking, so there's obviously
something else going on here that you're not making
explicit.  You need to provide a complete (preferbly
small) working example of the behaviour you describe.

You could also say

print_form() for 1..4;

hth
t
-- 
Somebody light this monkey.  AAAAGGGHHHH!!  Bad monkey!


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

Date: Mon, 25 Jun 2001 22:05:28 +0100
From: "Miles Davenport" <miles@explorer.demon.co.uk>
Subject: Re: begginers question
Message-Id: <993502722.6858.0.nnrp-01.d4e4dc01@news.demon.co.uk>

This is a multi-part message in MIME format.

------=_NextPart_000_001F_01C0FDC2.F16F7470
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

#!/usr/local/bin/perl

sub printForm() {
    my $subCounter =3D $_[0];

    print $subCounter;
}

for (my $counter =3D 1; $counter <=3D 4; $counter++) {
    &printForm($counter);
}


  "Umair Tariq Bajwa" <ub98aa@brocku.ca> wrote in message =
news:3B37800F.4A122E6F@brocku.ca...
Does any know what what i am doing wrong here.
I would like to call the function 4 times and i put it in a for loop. It =
just print only once.
for (1,2,3,4)
{
   print_form();
}
  I even tried this but no success.=20
  for (1..4)=20
  {=20
     print_form();
  }=20
  Thanks for your help.=20

  Umair=20


------=_NextPart_000_001F_01C0FDC2.F16F7470
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3103.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>#!/usr/local/bin/perl</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>sub printForm() {<BR>&nbsp;&nbsp;&nbsp; =
my=20
$subCounter =3D $_[0];</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; print=20
$subCounter;<BR>}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>for (my $counter =3D 1; $counter =
&lt;=3D 4; $counter++)=20
{<BR>&nbsp;&nbsp;&nbsp; &amp;printForm($counter);<BR>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV>"Umair Tariq Bajwa" &lt;<A=20
  href=3D"mailto:ub98aa@brocku.ca">ub98aa@brocku.ca</A>&gt; wrote in =
message <A=20
  =
href=3D"news:3B37800F.4A122E6F@brocku.ca">news:3B37800F.4A122E6F@brocku.c=
a</A>...</DIV><PRE>Does any know what what i am doing wrong =
here.</PRE><PRE>I would like to call the function 4 times and i put it =
in a for loop. It just print only once.</PRE><PRE>for (1,2,3,4)
{
&nbsp;&nbsp; print_form();
}</PRE>I even tried this but no success. <BR>for (1..4) <BR>{ =
<BR>&nbsp;&nbsp;=20
  print_form();<BR>}=20
  <P>Thanks for your help.=20
  <P>Umair </P></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_001F_01C0FDC2.F16F7470--



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

Date: Mon, 25 Jun 2001 18:12:39 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Checking for duplicates before appending to file
Message-Id: <tjevon22vfir39@corp.supernews.com>

David Soming (davsoming@lineone.net) wrote:
: I would like to check for duplicates in my database before appending:
: open (EMAILS, ">>address.txt");

Always check for the success of open.

: flock(EMAILS, 2);

Using the constants from Fcntl makes for more readable locks.

: print EMAILS "$email\n";

You should seek to the end of the file before printing, even though you
opened for append.  Another process could have written more between your
open and this print, while flock waited to get write access.

: flock(EMAILS, 8);

Doing an explicit lock release is almost always a bad idea.  Let close()
release the lock for you; it does so automatically.

: close (EMAILS);
: 
: This is a whole new ball game and "struggling" to say the least. I would
: appreciate it if anyone can help me incorporate some code to the existing
: above.
: I have this tangled mess...
: 
: open(EMAILS,"address.txt");
: @address=<EMAILS>;
: close(EMAILS);
: 
: $add = grep{ /$email{'address'}/i } @email;
: 
: if (@add) {
:  $errormessage = "The address you entered, <B>$email{'address'}</B> is
: already in our mailing list";
: }
: exit;
: 
: But then- Im only learning!

Usual idiom is to open for read-update (+<) with an exlusive lock, read in
the list, check for dups, and if no dup, seek to the end and write your
new record.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: Mon, 25 Jun 2001 18:18:34 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Checking for duplicates before appending to file
Message-Id: <tjf03qp6r6efd6@corp.supernews.com>

Benjamin Goldberg (goldbb2@earthlink.net) wrote:
: 	# after the while loop, we should be at the EOF...
: 	# which coincidentally is right where we want to write to.

Note that some OSs require a seek when switching from reading to writing,
even a no-op seek like seek(0, 1).  See 'perldoc -f seek' for details.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: Mon, 25 Jun 2001 19:25:07 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: Checking for duplicates before appending to file
Message-Id: <tjf03trfgcem72@corp.supernews.co.uk>

<snipped>
> #------------------------------------------------------------
> my $emails = 'address.txt';
> open (EMAILS, ">>$emails") or die ("Can't open $emails: $!");
> flock (EMAILS, 2);
> seek (EMAILS, 0, 0); # rewind
>
> my $found = 0;
> while (<EMAILS>) {
>   chomp;
>   if (/^$email{'address'}$/i) {
>     $found++;
>     last;
>   }
> }
>
> if ($found) {
>   my $errormessage = "The address you entered, <B>$email{'address'}</B>
> is already in our mailing list";
> } else {
>   seek (EMAILS, 0, 2); # fast forward to eof
>   print EMAILS "$email\n";
> }
>
> close (EMAILS); # flock (EMAILS, 8) not needed or advised!
> #------------------------------------------------------------
>
 Michael, I replaced my code with yours (exactly) and it still allows for
duplicates?
Would it have anything to do with scalar "my $emails" as my variable is
globally predefined elsewhere as: "$email" ?
Thanks too for the flock 8 advisory!
Cheers
--
David Soming
'Just a head-banger- doing what I do best'
______________




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

Date: Mon, 25 Jun 2001 22:46:21 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: Checking for duplicates before appending to file
Message-Id: <tjfbt765p6mdc4@corp.supernews.co.uk>

> use Fcntl qw(:flock);
> flock EMAILS, LOCK_EX
> or die "Could not gain flock for address.txt: $!\n";
> print EMAILS, $email, "\n";
> flock EMAILS, LOCK_UN;
> close EMAILS or die "close(address.txt) : $!\n"; # disk full?
>
<snipped>

> > open(EMAILS,"address.txt");
> > @address=<EMAILS>;
> > close(EMAILS);
>
> Just because you are just reading is no reason not to lock the file.
> And wouldn't it be better to open the file in read/write mode?
Yes I agree, but ...
>
> open( EMAILS, ">>", "address.txt" )
> or die "Could not open address.txt in rw mode: $!";

My server reports misconfiguration- even with chmod set at 755 or 777?
seems like "," ", " and/or the  line: die "Could not open address.txt in rw
mode: $!"; reports server misconfig too? (no further error details or access
to
logs)

> flock EMAILS, LOCK_EX
> or die "Could not gain flock for address.txt: $!\n";
>
> >
> > $add = grep{ /$email{'address'}/i } @email;
>
> grep in a scalar context?  Bleh.
lol
>
> while( <EMAILS> ) {
> next unless /^\Q$email{address}\E$/i;
> print <<"\t\tHEREDOC"
> The email address you entered, <B>$email{address}</B>
> is already in our mailing list.
> HEREDOC
> exit;
> }
The above reports Software error:
Can't find string terminator "\t\tThe email address you entered,
<B>$email{address}</B>is already in our mailing list." anywhere before EOF
What exactly does that mean? have I implimented this right...

while( <EMAILS> ) {
next unless /^\Q$email\E$/i;
print <<"\t\t The email address you entered, <B>$email{address}</B>is
already in our mailing list.";
print EMAILS $email{address}, "\n";
close EMAILS or die "close(address.txt) : $!\n"; # disk full?
exit;

> # after the while loop, we should be at the EOF...
> # which coincidentally is right where we want to write to.
> print EMAILS $email{address}, "\n";
> close EMAILS or die "close(address.txt) : $!\n"; # disk full?
> exit;
>
> There's no need to explicitly unlock the file, since that should
> automatically happen when the file is closed.
OK, thats understood.
>
> Note that I'm allowed to indent the string HEREDOC due to the fact that
> the indent (the \t\t) is part of the string being searched for.  If you
> change the indentation, do it in both places.  If your newsreader strips
> tabs, umm... get rid of the \t\t before the first string HEREDOC, or
> something.
By HEREDOC I'm assuming you mean my string "as above between these quotation
marks" or have I misunderstood? and what do you mean by "change it in BOTH
places" ?
>
> > if (@add) {
> >  $errormessage = "The address you entered, <B>$email{'address'}</B> is
> > already in our mailing list";
> > }
> > exit;
>
> --
> The longer a man is wrong, the surer he is that he's right.

IM having to debug remotely too because flock() is not implemented on my
platform, although I could comment out- but still get the above errors which
doesn't further narrow things down much.
Thanks for all your help
--
David Soming
'Just a head-banger- doing what I do best'
______________






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

Date: 25 Jun 2001 15:01:11 -0700
From: les_ander@yahoo.com (les ander)
Subject: counting matches
Message-Id: <a2972632.0106251401.2fb0676e@posting.google.com>

Hi,
I have a large string ($string) in which i have to 
search for number of occurences of a pattern that is in a hash table. I 
need to count the number of times this pattern occurs in the string
but the compiler complains. can someone correct my code below.. thanks

my $count;
my $sub_string;
my $len=length($string);

#i have a hash table %patterns_tbl which has all the patterns

for my $pattern(%patterns_tbl)
{
  for(my $i=0; $i<$len; $i++)
  {
     $sub_string=substr($string,$i,$len);
     $count=$sub_string =~ tr/$pattern/$pattern/; 
     $patterns_tbl{$pattern}=$count;
   }
   count=0;
}


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

Date: Mon, 25 Jun 2001 19:00:40 GMT
From: "Blnukem" <blnukem@hotmail.com>
Subject: E-mail help
Message-Id: <sTLZ6.37494$2w.5592796@news02.optonline.net>

Hi All
    I'm trying to send E-mail from a web form with 3 carbon copies and it
only sends to the first one. But in the E-mail it list that copies where
sent but there not here is my code.

open (MAIL,"|/bin/sendmail -t");
print MAIL "To: $FORM{'to'}\n";
print MAIL "From: $FORM{'from'}\n;
print MAIL "Cc:$FORM{'cc1'}, $FORM{'cc2'}, $FORM{'cc3'}\n";
print MAIL "Subject: $FORM{'subject'}\n\n";

print MAIL "$FORM{'body'}\n";

close (MAIL);





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

Date: Mon, 25 Jun 2001 15:09:51 -0500
From: Scott Yanoff <yanoff@yahoo.com>
To: Blnukem <blnukem@hotmail.com>
Subject: Re: E-mail help
Message-Id: <3B379A8F.41B70AC4@yahoo.com>

Blnukem wrote:
> 
> Hi All
>     I'm trying to send E-mail from a web form with 3 carbon copies and it
> only sends to the first one. But in the E-mail it list that copies where
> sent but there not here is my code.
> 
> open (MAIL,"|/bin/sendmail -t");
> print MAIL "To: $FORM{'to'}\n";
> print MAIL "From: $FORM{'from'}\n;
> print MAIL "Cc:$FORM{'cc1'}, $FORM{'cc2'}, $FORM{'cc3'}\n";

hmmm... for starters, try space-separating the CC instead of
comma-separating them.

Also, I am not sure you want to sent the direct results of a form into
the sendmail program.  You might want to make sure no one is entering in
funky characters first:

my $to = $FORM{'to'};
$to =~ s/some list of characters here//g;
print MAIL "To: $to\n";

Good luck,
-- 
-Scott
yanoff@yahoo.com | http://www.yanoff.org | AOL IM: SAY KJY


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

Date: Mon, 25 Jun 2001 15:54:02 -0500
From: Dale Bohl <dbohl@sgi.com>
Subject: Error Message
Message-Id: <3B37A4EA.AEBC2F2@sgi.com>


   Can anyone please explain what exactly this means?
I'm seeing this in stdout when I run a piece of
perl code.

Subroutine _MIPS_FPSET redefined at (eval 46) line 1 (#1)
    
    (W) You redefined a subroutine.  To suppress this warning, say
    
        {
        local $^W = 0;
        eval "sub name { ... }";
        }
    
Subroutine _MIPS_SZINT redefined at (eval 47) line 1 (#1)
Subroutine _MIPS_SZLONG redefined at (eval 48) line 1 (#1)
Subroutine _MIPS_SZPTR redefined at (eval 49) line 1 (#1)
Subroutine _MIPS_ISA redefined at (eval 50) line 1 (#1)
Subroutine _MIPS_SIM redefined at (eval 51) line 1 (#1)
Subroutine _MIPSEB redefined at (eval 52) line 1 (#1)
Subroutine MIPSEB redefined at (eval 53) line 1 (#1)
Subroutine _D_BSD_TYPES redefined at (eval 54) line 1 (#1)
Subroutine _POSIX_C_SOURCE redefined at (eval 55) line 1 (#1)
Subroutine _MIPSABI_SOURCE redefined at (eval 56) line 1 (#1)
Subroutine U redefined at (eval 57) line 1 (#1)
Subroutine F redefined at (eval 58) line 1 (#1)
Subroutine u redefined at (eval 59) line 1 (#1)
Subroutine uLL redefined at (eval 60) line 1 (#1)

-- 

Thanks,
Dale


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

Date: Mon, 25 Jun 2001 19:40:53 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: finding a file in a directory and reading it
Message-Id: <3b3793c4.7196$fb@news.op.net>

In article <52fb0298.0106241929.740b4656@posting.google.com>,
Nina <nina_samimi@yahoo.com.au> wrote:
>my @tempdir;
>opendir(DIR, $mns_dir) || die("Cannot open directory");
>while (my $tempfiles = readdir DIR) {
>  print $tempfiles  if $tempfiles =~
>/RPTPRINT.MNS206AR.24Jun01_13.37.48.Z/;
>}
>closedir DIR;
>
>
>it gives me an error message "Use of uninitialized value at
>qf_system_blast.pl line 179."

Which line is 179?

>This file is compressed ".Z", can I open it compressed or no?

Yes.  try

        open ZFILE, "compress -dc $filename |" or die ...;

If this 'open' succeeds, then you can read the uncompressed data from
ZFILE as usual.




-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Mon, 25 Jun 2001 22:50:49 +0100
From: "Pat McCourt" <patmccourt@eircom.net>
Subject: Re: Getting http file and parsing it. Help please.
Message-Id: <CfOZ6.11121$Fk7.99690@news.indigo.ie>

Whitley,

First step - try to run the script from a local machine.  Your script brings
back the blomberg page, but fails to parse it as you would wish, so you need
to work on that (sort that on a local machine first).

Then your server 500 error.  This most often happens because you do not have
permissions set correctly, probably to write to the filehandle.

Pat

Whitey <whitey@wherever.com> wrote in message
news:whitey-E3DB66.01450223062001@news1.rdc1.sfba.home.com...
> I have the following code that I would like to have fetch the index page
> and strip everything between the PETROLEUM tag and the BbgElogin2 text
> to be spit out to a file. I, for the life of me, cannot get it to work
> properly. I am getting 500 INTERNAL SERVER ERROR messages, and I cannot
> track down a log file to tell me what's going wrong. I don't think this
> file is complete, either. Could someone help me please?
>
>
>
> #!/usr/bin/perl
>
> use LWP::Simple;
> use LWP::UserAgent;
>
> $_ = get ("http://www.bloomberg.com/energy/index.html");
> $data =~ /<!---------------PETROLEUM-----------------> (.*) <map
> name="BbgELogin2">/m;
> open (FH,"./file.txt") ||die"$!";
> print FH $_;
> close FH;




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

Date: Mon, 25 Jun 2001 15:26:53 -0700
From: Peter <rig01@yahoo.com>
Subject: HELP PLZ; How to remove all the nonprintables characters in a large file . HELP!!!
Message-Id: <mcefjt8rgatohpnmnrqp58as8gac4pr27h@4ax.com>

Hi :


I have a large file, with garbage in some lines.
If you want to remove all the nonprintables characters (garbage),
How to do this in Perl?

Thanks in Adavace

Peter


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

Date: Mon, 25 Jun 2001 21:58:22 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: HELP PLZ; How to remove all the nonprintables characters in a large file . HELP!!!
Message-Id: <tjfcvuknf7u54c@corp.supernews.com>

In article <mcefjt8rgatohpnmnrqp58as8gac4pr27h@4ax.com>,
    Peter  <rig01@yahoo.com> wrote:

: I have a large file, with garbage in some lines.
: If you want to remove all the nonprintables characters (garbage),
: How to do this in Perl?

    #! /usr/local/bin/perl -w

    while (<>) {
        s/[[:^print:]]+//g;
        print;
    }

You'll need a post-5.6 perl to use the POSIX-style character classes.

Hope this helps,
Greg


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

Date: 25 Jun 2001 12:35:53 -0700
From: asim@cognizo.com (Asim Beg)
Subject: Help with a regular expression
Message-Id: <4763ded4.0106251135.5259f301@posting.google.com>

I am looking for a regular expression to parse the following:
its basically part of a US Address.

<city>, <2 letter state> <zip>

e.g 

Redwood City, CA 94065


Thanks
Asim


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

Date: Mon, 25 Jun 2001 19:44:20 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Help with a regular expression
Message-Id: <3b37947a.71ab$2c6@news.op.net>

In article <4763ded4.0106251135.5259f301@posting.google.com>,
Asim Beg <asim@cognizo.com> wrote:
>I am looking for a regular expression to parse the following:
>its basically part of a US Address.
>
><city>, <2 letter state> <zip>
>
>e.g 
>
>Redwood City, CA 94065

Perhaps you might like this:

        ($city, $state, $zip) = ($address =~ /([^,]+),\s*(\w\w)\s+(\d{5})/);


-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Mon, 25 Jun 2001 20:15:57 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Help with a regular expression
Message-Id: <tjf6vt2gqjn35@corp.supernews.com>

Asim Beg (asim@cognizo.com) wrote:
: I am looking for a regular expression to parse the following:
: its basically part of a US Address.
: 
: <city>, <2 letter state> <zip>
: e.g 
: Redwood City, CA 94065

  my ($city, $state, $zip) = $str =~ /(.*?),\s+([A-Z]{2})\s+(\d{5})/;

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: Mon, 25 Jun 2001 20:15:41 +0000
From: silver+news@phoenyx.net (Karen J. Cravens)
Subject: Re: Help with a regular expression
Message-Id: <Xns90CB9B655FAFAphoenyx@192.168.0.3>

mjd@plover.com (Mark Jason Dominus) wrote in
<3b37947a.71ab$2c6@news.op.net>: 

>In article <4763ded4.0106251135.5259f301@posting.google.com>,
>Asim Beg <asim@cognizo.com> wrote:
>> I am looking for a regular expression to parse the following:
>> its basically part of a US Address.
>><city>, <2 letter state> <zip>
>> e.g 
>> Redwood City, CA 94065
>
>Perhaps you might like this:
>
>        ($city, $state, $zip) = ($address =~
>        /([^,]+),\s*(\w\w)\s+(\d{5})/); 

I'd replace (\d{5}) with something that would also pick up 9-digit zips, 
unless you absolutely know you're not going to get any.  (\d{5}\-
{0,1}\d{0,4}) or something similar, depending on how much you want to 
depend on reliability of incoming data.


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

Date: Mon, 25 Jun 2001 19:33:51 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: How do I cope with pound (currency) sign?
Message-Id: <3b379203.714c$112@news.op.net>

In article <m1lmmgh391.fsf@da-nu.com>, David Wake  <dn131@yahoo.com> wrote:
>I'm parsing some raw HTML from some British websites, and some of them
>contain the British pound (currency) sign in their raw HTML.  Can
>anyone tell me how I could parse this symbol in a regular expression?

Pound signs aren't special in regular expressions, so if you want to
match on with a regex, write it the same way in the regex as it
appears in the HTML.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Mon, 25 Jun 2001 14:31:45 -0400
From: "David J. Marcus" <djmarcus@ex-pressnet.com>
Subject: memory foot print of perl.exe is huge!!
Message-Id: <tjf0s2apkj192e@corp.supernews.com>

Hi

I'm running AS version 5.6.1 on Win2K pro.

Using the Task manager I notice that the "MemUsage" of any perl process is
13+MB. I was expecting an order of magnitude less.

Any ideas what is going on? As usual, AS does not respond to queries without
a support contract (yech, boo).

-TIA
David




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

Date: Mon, 25 Jun 2001 14:18:40 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Newbie - Compare text files
Message-Id: <3b37aab0$1@news.microsoft.com>

<plarkinNOSPAM@indeliblelink.com> wrote in message
news:B75CC7D7.837B%plarkinNOSPAM@indeliblelink.com...
> I have a comma delimited file or approx 14,000 lines.  Each line has about
> 35 fields.  I import it into a MySQL database.  I get sent an updated file
> each day.
> When I get a new updated file, I'd like to compare it to yesterdays file.
> If a new record was added in the new file, write that line to a
"NewRecords"
> file.  If the new file is missing a line from the old file, write that
line
> to an "RemovedRecords" file.  Finally, any record that has changed in any
> way, write that to a "ChangedRecord" file.

If the sequence of the existing entries in the file stays the same from day
to day then there is an easier way which doesn't involve Perl: use "diff"
(comes with every Unix, also available for Windows for free).
diff will create a detailed report (many options available) about which
lines have been added, deleted or modified.

This doesn't work if the the sequence of the lines changes. In that case you
may want to try to sort the files (by whatever criteria) first before
comparing them. Again, this is a job that can be done without Perl, just use
"sort" (same disclaimer as for diff).

If it gets more complicated than that then probably Perl is the better
solution.
See the FAQ6 "How do I compute the difference of two arrays" for one
approach.
Another approach is to search for "diff" on CPAN modules. The very first
entry points you to
      "Algorithm-Diff-1.10: Compute `intelligent' differences between two
files / lists"


jue




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

Date: Mon, 25 Jun 2001 15:04:09 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: Perl *is* strongly typed (was Re: Perl description)
Message-Id: <Pine.SUN.4.33.0106251452520.18468-100000@mamba.cs.Virginia.EDU>

On Mon, 25 Jun 2001, J=FCrgen Exner wrote:

> "David Coppit" <newspost@coppit.org> wrote in message
> news:Pine.SUN.4.33.0106242149300.7403-100000@mamba.cs.Virginia.EDU...
> > True enough, but that's not enough to say that Perl has strong typing.
> > What about string versus numeric types?
>
> Well, there is no data type "string" and no data type "numeric/int/real/"=
 in
> Perl to begin with. In so far your statement (as true as it is) is beside
> the point.

That's fair. I guess I'm picking a different nit. :) I've been burned
a couple times by the fact that Perl insufficiently hides the
difference between numeric and string types. In other words, Perl's
scalar type is really the composition of at least two only
partially-compatible types.

The code I posted illustrates this. Two ostensibly equivalent scalars
behaved differently under the same "closure of operations" on scalars.
e.g. " 3 . '' " is a different scalar subtype than " 3 ".

More recently, I ran into this problem trying to compare data
structures using Storable. One data structure had a stringified
version of a number. Of course the frozen data were not equivalent,
even though they were both of the "scalar" type.

Ideally there would be some sort of technique in place to make all
scalars canonical:

  if (Is_A_Numeric_String($scalar))
  {
    Make_String_Scalar_Numeric_Scalar($scalar);
  }

Of course, no one would implement such an inefficient thing. :)

David



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

Date: 25 Jun 2001 16:36:00 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Perl *is* strongly typed (was Re: Perl description)
Message-Id: <m3hex4s3f3.fsf@mumonkan.sunstarsys.com>

David Coppit <newspost@coppit.org> writes:

> The code I posted illustrates this. Two ostensibly equivalent scalars
> behaved differently under the same "closure of operations" on scalars.
> e.g. " 3 . '' " is a different scalar subtype than " 3 ".

I doubt you can find any Perl that treats ("3") different than (3).
Your prior code shows that (1/3 . '') is slightly different from (1/3),
but not in any meaningful sense:

  % perl -wle 'printf "%s\n%.16g\n", 1/3, 1/3;'
  0.333333333333333
  0.3333333333333333
  % perl -wle 'print 3 * sprintf "%.16g", 1/3'
  1
  % perl -wle 'printf "%.14g\n", 3 * (1/3 . "")'
  1
  % perl -wle 'print 3 * (1/3 . "3")'
  1

> More recently, I ran into this problem trying to compare data
> structures using Storable. One data structure had a stringified
> version of a number. Of course the frozen data were not equivalent,
> even though they were both of the "scalar" type.

Were the numbers floats or ints?
 
> Ideally there would be some sort of technique in place to make all
> scalars canonical:
> 
>   if (Is_A_Numeric_String($scalar))
>   {
>     Make_String_Scalar_Numeric_Scalar($scalar);
>   }
> 
> Of course, no one would implement such an inefficient thing. :)

I sure hope not- perl is supposed to do this all by itself.

-- 
Joe Schaefer    "The opposite of a correct statement is a false statement. The
                  opposite of a profound truth may well be another profound
                                           truth."
                                               --Niels Bohr



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

Date: Mon, 25 Jun 2001 23:54:23 +0200
From: Buggs <buggs-clpm@splashground.de>
Subject: Re: Perl *is* strongly typed (was Re: Perl description)
Message-Id: <9h8bo7$h9a$01$1@news.t-online.com>

Joe Schaefer wrote:

> David Coppit <newspost@coppit.org> writes:
> 
>> The code I posted illustrates this. Two ostensibly equivalent scalars
>> behaved differently under the same "closure of operations" on scalars.
>> e.g. " 3 . '' " is a different scalar subtype than " 3 ".
> 
> I doubt you can find any Perl that treats ("3") different than (3).
> Your prior code shows that (1/3 . '') is slightly different from (1/3),
> but not in any meaningful sense:
>

On initialization there is a difference between "3" and 3.

perl -MO=Terse -e '$foo = 3; $bar = "3";'

LISTOP (0x804ea80) leave [1]
    OP (0x80baec8) enter
    COP (0x805a280) nextstate
    BINOP (0x804eac0) sassign
        SVOP (0x804eae0) const  IV (0x804c218) 3
        UNOP (0x804eb20) null [15]
            SVOP (0x804eb00) gvsv  GV (0x805bd9c) *foo
    COP (0x805a300) nextstate
    BINOP (0x804e9e0) sassign
        SVOP (0x804ea20) const  PV (0x805bdc0) "3"
        UNOP (0x804ea00) null [15]
            SVOP (0x804ea60) gvsv  GV (0x805bd30) *bar


I'm not sure if this qualifies as "treat", but I'd say so.

Buggs


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

Date: Mon, 25 Jun 2001 21:56:57 +0100
From: "Miles Davenport" <miles@explorer.demon.co.uk>
Subject: Perl CGI - capturing return values with system calls
Message-Id: <993502214.6601.0.nnrp-01.d4e4dc01@news.demon.co.uk>

One a solaris 2.8 box, running apache webserver -
I have a simple perl CGI which has a number of system calls.
One of the calls - a shell script on a remote server using:

system (ssh server myScript.sh).

This script is not being executed consistently, as the previous command:
system (scp filename.tar server:/directory) does not ALWAYS (seems to be if
the tar file is large) return.

My queries include:

Is there a reliable way to capture the return from a system call to the perl
environment ?
Has anyone ever had problems making system(scp) calls when the filesize is
large - this may prevent control being returned to the perl env ?

Any help would be appreciated.

thanks

Miles







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

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.  

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 V10 Issue 1191
***************************************


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