[22599] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4820 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 5 18:06:16 2003

Date: Sat, 5 Apr 2003 15:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 5 Apr 2003     Volume: 10 Number: 4820

Today's topics:
        Accessing form data via tied hash <noreply@gunnar.cc>
    Re: Accessing form data via tied hash <usenet@tinita.de>
    Re: Accessing form data via tied hash <noreply@gunnar.cc>
        Addition in substitution <brflaming@yahoo.com>
    Re: Addition in substitution <grazz@nyc.rr.com>
    Re: Addition in substitution (Tad McClellan)
        array shift (AGoodGuyGoneBad)
    Re: array shift <mbudash@sonic.net>
    Re: array shift (Jay Tilton)
    Re: array shift <jurgenex@hotmail.com>
    Re: array shift (AGoodGuyGoneBad)
        Checkbox  Values Into a DB <jessicak@nac.net>
        Database overwriting itself (spyderscripts)
        FAQ change? (was: Re: regex question) <bongie@gmx.net>
        get name of previous sub that called the actual sub <pilsl_usenet@goldfisch.at>
    Re: get name of previous sub that called the actual sub <grazz@nyc.rr.com>
    Re: get name of previous sub that called the actual sub <abigail@abigail.nl>
    Re: looking for duplicates <bongie@gmx.net>
    Re: LWP post problem <mbudash@sonic.net>
    Re: open fails with filename starting with space <ewt@avajadi.org>
    Re: open fails with filename starting with space <jurgenex@hotmail.com>
    Re: perl's expat.so <shirsch@adelphia.net>
        PHP Code to PERL conversion... (Vijoy Varghese)
    Re: PHP Code to PERL conversion... (Tad McClellan)
    Re: Reformated Why won't this work. <Verbalx2@hotmail.com>
    Re: regular expressions: newbie question <barryk2@SPAM-KILLER.mts.net>
    Re: Stubbing FileHandle.pm <grazz@nyc.rr.com>
    Re: Substitution won't match for me <wksmith@optonline.net>
    Re: Substitution won't match for me <hiro@asari.net>
    Re: Substitution won't match for me (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 05 Apr 2003 23:00:56 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Accessing form data via tied hash
Message-Id: <b6ng8k$71ekv$1@ID-184292.news.dfncis.de>

This is what I did when first using CGI.pm for parsing form data:

     use CGI 'param';
     for (param()) { $in{$_} = param($_) }

In other words, the form data was stored as key/value pairs in a hash.

Then I discovered this option:

     use CGI;
     %in = new CGI->Vars;

However, since the 'Vars' function isn't available in older versions 
of CGI.pm, I replaced that with:

     use CGI;
     tie %in, new CGI;

Can somebody help me explain what I'm actually doing? Does this mean 
that I avoid to load an extra copy of the form data into memory? And 
is there any disadvantage to tie the hash directly, as in the last 
example, compared to using the 'Vars' function?

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: 5 Apr 2003 21:58:51 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Accessing form data via tied hash
Message-Id: <tinhcw5mf$27s$tina@news01.tinita.de>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> This is what I did when first using CGI.pm for parsing form data:

>      use CGI 'param';
>      for (param()) { $in{$_} = param($_) }

that doesn't handle multi-valued (e.g. select or checkboxes)
fields correctly.

> In other words, the form data was stored as key/value pairs in a hash.

> Then I discovered this option:

>      use CGI;
>      %in = new CGI->Vars;

> However, since the 'Vars' function isn't available in older versions 
> of CGI.pm, I replaced that with:

Vars() is actually older than param() (from cgi-lib.pl) and it's only in
CGI.pm to provide compatibility with cgi-lib.pl.
so why did you change to Vars(), anyway?

>      use CGI;
>      tie %in, new CGI;

> Can somebody help me explain what I'm actually doing? Does this mean 
> that I avoid to load an extra copy of the form data into memory? And 
> is there any disadvantage to tie the hash directly, as in the last 
> example, compared to using the 'Vars' function?

i didn't try it out, but as it is doing the same as Vars it
should be fine.
btw, you can just say "tie %in, CGI". it will create a new CGI-object
for you.

hth, tina
-- 
http://www.tinita.de/     \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/   \     / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/   \    \ _,_\ __/\ __/_| /__/ perception
http://www.tinita.de/peace/link.html - Spread Peace


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

Date: Sun, 06 Apr 2003 00:35:55 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Accessing form data via tied hash
Message-Id: <b6nlr6$798gp$1@ID-184292.news.dfncis.de>

Tina Mueller wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>>This is what I did when first using CGI.pm for parsing form data:
>> 
>>     use CGI 'param';
>>     for (param()) { $in{$_} = param($_) }
> 
> that doesn't handle multi-valued (e.g. select or checkboxes)
> fields correctly.

I know. Not an issue in this case.

>>Then I discovered this option:
>> 
>>     use CGI;
>>     %in = new CGI->Vars;
>> 
>> 
>>However, since the 'Vars' function isn't available in older versions 
>>of CGI.pm, I replaced that with:
> 
> Vars() is actually older than param() (from cgi-lib.pl) and it's only in
> CGI.pm to provide compatibility with cgi-lib.pl.
> so why did you change to Vars(), anyway?

I was (still am) hoping that I with that avoid loading an extra copy 
of the form data into memory.

Anybody who can tell me if I have understood that correctly?

>>     use CGI;
>>     tie %in, new CGI;
>> 
>>[snip] 
>>is there any disadvantage to tie the hash directly, as in the last 
>>example, compared to using the 'Vars' function?
> 
> i didn't try it out, but as it is doing the same as Vars it
> should be fine.
> btw, you can just say "tie %in, CGI". it will create a new CGI-object
> for you.

Okay, thanks, Tina.

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Sat, 05 Apr 2003 20:03:36 GMT
From: "Blakis" <brflaming@yahoo.com>
Subject: Addition in substitution
Message-Id: <sEGja.208$7T4.203@newssvr16.news.prodigy.com>

I'm trying to update the version number in a bunch of Java files using
Perl. The Java files all have a line similar to the following:

 * @version 1.0.4

I want my Perl script to increment the last number by one. Here's the
substitution I'm using:

$lines =~ s/( \* \@version \d\.\d\.)(\d).*/$1$2++/);

Where $lines contains the contents of the entire Java file. Instead of
getting what I want:

 * @version 1.0.5

I instead get this:

 * @version 1.0.4++

How can I make it so that the ++ in the substitution actually
increments the integer instead of tacking it on to the end of the
string? Thanks...




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

Date: Sat, 05 Apr 2003 22:37:39 GMT
From: Steve Grazzini <grazz@nyc.rr.com>
Subject: Re: Addition in substitution
Message-Id: <TUIja.1398$py2.243@twister.nyc.rr.com>

Blakis <brflaming@yahoo.com> wrote:
> I'm trying to update the version number in a bunch of Java files using
> Perl. The Java files all have a line similar to the following:
> 
>  * @version 1.0.4
> 
> I want my Perl script to increment the last number by one. Here's the
> substitution I'm using:
> 
> $lines =~ s/( \* \@version \d\.\d\.)(\d).*/$1$2++/);
> 

You'd need the /e modifier (and pre-increment).

    $ perldoc perlop

And there's an ant thigamabob for stamping files with the
project version.  (Not to mention "$Revision: $", etc)

-- 
Steve


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

Date: Sat, 5 Apr 2003 16:51:36 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Addition in substitution
Message-Id: <slrnb8unfo.6ca.tadmc@magna.augustmail.com>

Blakis <brflaming@yahoo.com> wrote:
> I'm trying to update the version number in a bunch of Java files using
> Perl. The Java files all have a line similar to the following:
> 
>  * @version 1.0.4
> 
> I want my Perl script to increment the last number by one. Here's the
> substitution I'm using:
> 
> $lines =~ s/( \* \@version \d\.\d\.)(\d).*/$1$2++/);
                                                    ^
                                                    ^
Where is the open paren to match that closing paren?


    Do not re-type Perl code
        Use copy/paste or your editor's "import" function rather than
        attempting to type in your code. If you make a typo you will get
        followups about your typos instead of about the question you are
        trying to get answered.


> How can I make it so that the ++ in the substitution actually
> increments the integer instead of tacking it on to the end of the
> string? 

use the s///e modifier:

   s/( \* \@version \d\.\d\.)(\d).*/$1 . ($2+1)/e;


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 05 Apr 2003 18:03:16 GMT
From: agoodguygonebad@aol.com (AGoodGuyGoneBad)
Subject: array shift
Message-Id: <20030405130316.16855.00000630@mb-fh.aol.com>

I need to shift an array of N numbers.
if N=8 and the sequence is 50,0,44,69,0,0,200,11
the result should be 0,0,200,11,50,0,44,69
Each numeric value is <=255 if that helps

Please note it's shifting, not sorting the array.

I was trying to create N strings of the numbers so
S(0) = 50044690020011
S(4) = 00200115004469

then I can take the VAL of each string, see which is smallest
then shift the field data S(n) times.

I might later decide to shift the data, so the longest string of alike numbers
are on the left, then subtract that number from itself, and all the rest
(negative numbers will need to be added to 256)
The values aren't important, just the sequence they are in, and their value to
each other.
ie 169,11,50,50,0,30,44,255, becomes 50,50,0,30,44,255,169,11
becomes 0,0,206,236,250,205,119,217
(recheck, add 50 to all and mod 256)
Steve


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

Date: Sat, 05 Apr 2003 19:19:16 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: array shift
Message-Id: <mbudash-7F5A96.11191605042003@typhoon.sonic.net>

In article <20030405130316.16855.00000630@mb-fh.aol.com>,
 agoodguygonebad@aol.com (AGoodGuyGoneBad) wrote:

> I need to shift an array of N numbers.
> if N=8 and the sequence is 50,0,44,69,0,0,200,11
> the result should be 0,0,200,11,50,0,44,69
> Each numeric value is <=255 if that helps
> 
> Please note it's shifting, not sorting the array.
> 
> I was trying to create N strings of the numbers so
> S(0) = 50044690020011
> S(4) = 00200115004469
> 
> then I can take the VAL of each string, see which is smallest
> then shift the field data S(n) times.
> 
> I might later decide to shift the data, so the longest string of alike numbers
> are on the left, then subtract that number from itself, and all the rest
> (negative numbers will need to be added to 256)
> The values aren't important, just the sequence they are in, and their value to
> each other.
> ie 169,11,50,50,0,30,44,255, becomes 50,50,0,30,44,255,169,11
> becomes 0,0,206,236,250,205,119,217
> (recheck, add 50 to all and mod 256)
> Steve

i don't know about anyone else, but i haven't the slightest idea what it 
is you're trying to accomplish in the long run... however, to shift (i 
would call it "rotate") an array once, taking the first element and 
making it the last:

push @array, shift @array;

or, in the other direction, taking the last element and making it the 
first:

unshift @array, pop @array;

hth-

-- 
Michael Budash


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

Date: Sat, 05 Apr 2003 19:34:28 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: array shift
Message-Id: <3e8f2565.4465624@news.erols.com>

agoodguygonebad@aol.com (AGoodGuyGoneBad) wrote:

: I need to shift an array of N numbers.
: if N=8 and the sequence is 50,0,44,69,0,0,200,11
: the result should be 0,0,200,11,50,0,44,69

"Shift" has a definite meaning in Perl, and that's not it.
I would instead call that rotation.

It's not terribly clear how the new first element is chosen, but an
array slice would be useful.

    my @ary = (50, 0, 44, 69, 0, 0, 200, 11 );
    my $pivot = 4;
    @ary = @ary[ $pivot .. $#ary, 0 .. $pivot-1 ];

: Each numeric value is <=255 if that helps
:
: I was trying to create N strings of the numbers so
: S(0) = 50044690020011
: S(4) = 00200115004469
: 
: then I can take the VAL of each string, see which is smallest
: then shift the field data S(n) times.

That feels fragile and unnecessarily complicated.

: I might later decide to shift the data, so the longest string of alike numbers
: are on the left, then subtract that number from itself, and all the rest
: (negative numbers will need to be added to 256)
:
: The values aren't important, just the sequence they are in, and their value to
: each other.
: ie 169,11,50,50,0,30,44,255, becomes 50,50,0,30,44,255,169,11
: becomes 0,0,206,236,250,205,119,217
: (recheck, add 50 to all and mod 256)

So you want the new array to begin with the longest sequence of
identical values?  The explanation is really muddled, but I think I've
got a handle on it.

How's this grab you?

    #!perl
    use warnings;
    use strict;

    my @ary = (169,11,50,50,0,30,44,255);
    print "Before: @ary\n";

    # find longest sequence of identical values
    my $str = pack 'C*', @ary;
    my $longest = 0;
    my $pivot = 0;
    while( $str =~ /((.)\2+)/gs ) {
        #                     ^
        # /s modifier because \n may be present
        if( length($1) > $longest ) {
            $longest = length($1);
            $pivot = pos($str) - $longest;
        }
    }

    # Rotate array and normalize values
    @ary = map (
             ($_ - $ary[$pivot]) % 256,
             @ary[ $pivot .. $#ary, 0 .. $pivot-1 ]
           );
    print "After: @ary\n";



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

Date: Sat, 05 Apr 2003 21:51:08 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: array shift
Message-Id: <gdIja.14061$aQ3.2938@nwrddc02.gnilink.net>

AGoodGuyGoneBad wrote:
> I need to shift an array of N numbers.

perldoc -f shift

> if N=8 and the sequence is 50,0,44,69,0,0,200,11
> the result should be 0,0,200,11,50,0,44,69

That's not shift, that's rotate.
Don't know if there is a module that does it already (probably there is, did
you check CPAN?) but otherwise it's rather simple to do it using array
slices:

@new = (@old[n..$#old], @old[0..$n-1]);

jue




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

Date: 05 Apr 2003 21:53:45 GMT
From: agoodguygonebad@aol.com (AGoodGuyGoneBad)
Subject: Re: array shift
Message-Id: <20030405165345.04368.00000299@mb-fh.aol.com>

>Subject: Re: array shift
>From: tiltonj@erols.com  (Jay Tilton)
>Date: 4/5/03 11:34 AM Pacific Standard Time
>Message-id: <3e8f2565.4465624@news.erols.com>
>
>agoodguygonebad@aol.com (AGoodGuyGoneBad) wrote:
>
>: I need to shift an array of N numbers.
>: if N=8 and the sequence is 50,0,44,69,0,0,200,11
>: the result should be 0,0,200,11,50,0,44,69
>
>"Shift" has a definite meaning in Perl, and that's not it.
>I would instead call that rotation.
>
>It's not terribly clear how the new first element is chosen, but an
>array slice would be useful.
>
>    my @ary = (50, 0, 44, 69, 0, 0, 200, 11 );
>    my $pivot = 4;
>    @ary = @ary[ $pivot .. $#ary, 0 .. $pivot-1 ];
>
>: Each numeric value is <=255 if that helps
>:
>: I was trying to create N strings of the numbers so
>: S(0) = 50044690020011
>: S(4) = 00200115004469
>: 
>: then I can take the VAL of each string, see which is smallest
>: then shift the field data S(n) times.
>
>That feels fragile and unnecessarily complicated.
>
>: I might later decide to shift the data, so the longest string of alike
>numbers
>: are on the left, then subtract that number from itself, and all the rest
>: (negative numbers will need to be added to 256)
>:
>: The values aren't important, just the sequence they are in, and their value
>to
>: each other.
>: ie 169,11,50,50,0,30,44,255, becomes 50,50,0,30,44,255,169,11
>: becomes 0,0,206,236,250,205,119,217
>: (recheck, add 50 to all and mod 256)
>
>So you want the new array to begin with the longest sequence of
>identical values?  The explanation is really muddled, but I think I've
>got a handle on it.
>
>How's this grab you?
>
>    #!perl
>    use warnings;
>    use strict;
>
>    my @ary = (169,11,50,50,0,30,44,255);
>    print "Before: @ary\n";
>
>    # find longest sequence of identical values
>    my $str = pack 'C*', @ary;
>    my $longest = 0;
>    my $pivot = 0;
>    while( $str =~ /((.)\2+)/gs ) {
>        #                     ^
>        # /s modifier because \n may be present
>        if( length($1) > $longest ) {
>            $longest = length($1);
>            $pivot = pos($str) - $longest;
>        }
>    }
>
>    # Rotate array and normalize values
>    @ary = map (
>             ($_ - $ary[$pivot]) % 256,
>             @ary[ $pivot .. $#ary, 0 .. $pivot-1 ]
>           );
>    print "After: @ary\n";
>

works great
I added
if $longest ne 0 {
just before the
 @ary=map

So nothing is changed if there are no repeating numbers
Thanks
Steve


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

Date: Sat, 05 Apr 2003 17:23:36 -0500
From: Jessica <jessicak@nac.net>
Subject: Checkbox  Values Into a DB
Message-Id: <3e8f582e$1_1@nntp2.nac.net>

Hi,

I'm using Perl to input results of a form into a MySQL database.

I'm using the CGI module

The problem is with the checkbox's (Box1 name="interests" 
value="hiking", Box2 name="interests" value="skiing", Box3 
name="interests" value="swiming" etc...

Everything else on the form is working but with the checkbox values I'm 
only getting the first checked value put into the DB. I know that this 
probably has something to do with arrays but I'm clueless as what to do 
about looping through it to get a string to put into a variable (with a 
space between each value) that I can put into the db.

Any one have a snippet of code and could you give a brief description of 
what it's doing??

Thank You,

Jessica



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

Date: 5 Apr 2003 13:21:08 -0800
From: sulfericacid@qwest.net (spyderscripts)
Subject: Database overwriting itself
Message-Id: <32b6332f.0304051321.4802f625@posting.google.com>

Can someone tell me why my database keeps rewriting itself only saving
the last value given to it?

    if ( param('email') ne "" ) {
        tie %emails, 'SDBM_File', $list, O_CREAT | O_RDWR, 0644;

        if ( !tied %emails ) {
            warn("database unsuccessful $!.\n");
        }
        $emails{$email} = "test";
        print "Email address added to database!";
        foreach ( sort keys(%emails) ) {
        print "$_ => $emails{$_}<br>";
        }


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

Date: Sat, 05 Apr 2003 21:00:39 +0200
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: FAQ change? (was: Re: regex question)
Message-Id: <3162217.5Ltgt9AxnB@nyoga.dubu.de>

Anno Siegel wrote:
> Tore Aursand <tore@aursand.no> wrote in comp.lang.perl.misc:
>>   1 while $string =~ s/^(\d+)(\d{4})/$1-$2/;
>> 
>> I modified the regular expression above so that it should work with
>> your data.
> 
> Ah, that's a nice one.  As the FAQ shows, it can be done in a single
> regex, but your's is much easier on the eyes.

Unfortunately (IMHO), a similar solution has been removed from the FAQ
in favor of the single regex.  I don't mind Benjamin's very smart
solution, but I think that many readers would prefer a code that's not
only smart but also easy to understand, so I would suggest to combine
the old (pre-5.8.0) and the new answers in the FAQ.

See for yourself:
http://www.perldoc.com/perl5.6.1/pod/perlfaq5.html#How-can-I-output-my-numbers-with-commas-added-
http://www.perldoc.com/perl5.8.0/pod/perlfaq5.html#How-can-I-output-my-numbers-with-commas-added-
(URLs might be broken in your newsreader, please concat as needed.)

Comments welcome.

Ciao,
        Harald
-- 
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
"Have a nice day!" - "No, thank you. I have other plans."



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

Date: Sat, 5 Apr 2003 23:03:04 +0200
From: peter pilsl <pilsl_usenet@goldfisch.at>
Subject: get name of previous sub that called the actual sub
Message-Id: <3e8f44c3$1@e-post.inode.at>


logging/debugging is an important feature.
every methods in my project uses a logit-method at least on time.

for finding error more quickly it would be nice if the logit-method could 
log the name of the method from where it was involved.

sub something{
  my $o=shift;
  $o->logit('start');
}

sub logit{
   my $o=shift;
    my $text=shift;
   .
    my $caller=magic perl wonders
   ...
   print FH,$caller,$text;
}

is this possible to access the "sub-stack"  in perl easily and at 
reasonable speed ?

thnx,
peter


-- 
peter pilsl
pilsl_usenet@goldfisch.at
http://www.goldfisch.at



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

Date: Sat, 05 Apr 2003 21:11:37 GMT
From: Steve Grazzini <grazz@nyc.rr.com>
Subject: Re: get name of previous sub that called the actual sub
Message-Id: <dEHja.1366$Tu4.1186214@twister.nyc.rr.com>

peter pilsl <pilsl_usenet@goldfisch.at> wrote:
> 
> it would be nice if the logit-method could log the name of 
> the method from where it was involved. [...]
> 
>     my $caller=magic perl wonders

(self-answering)

      my $caller = (caller 1)[3];

-- 
Steve


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

Date: 05 Apr 2003 21:18:23 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: get name of previous sub that called the actual sub
Message-Id: <slrnb8ui0v.ias.abigail@alexandra.abigail.nl>

peter pilsl (pilsl_usenet@goldfisch.at) wrote on MMMDIV September
MCMXCIII in <URL:news:3e8f44c3$1@e-post.inode.at>:
;;  
;;  logging/debugging is an important feature.
;;  every methods in my project uses a logit-method at least on time.
;;  
;;  for finding error more quickly it would be nice if the logit-method could 
;;  log the name of the method from where it was involved.
;;  
;;  sub something{
;;    my $o=shift;
;;    $o->logit('start');
;;  }
;;  
;;  sub logit{
;;     my $o=shift;
;;      my $text=shift;
;;     .
;;      my $caller=magic perl wonders
;;     ...
;;     print FH,$caller,$text;
;;  }
;;  
;;  is this possible to access the "sub-stack"  in perl easily and at 
;;  reasonable speed ?


Yes. And the function to be called is called, "caller".

    my $caller = (caller (1)) [3];

should do the trick.


Abigail
-- 
$_ = "\112\165\163\1648\141\156\157\164\150\145\1628\120\145"
   . "\162\1548\110\141\143\153\145\162\0128\177"  and &japh;
sub japh {print "@_" and return if pop; split /\d/ and &japh}


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

Date: Sat, 05 Apr 2003 23:42:01 +0200
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: looking for duplicates
Message-Id: <1200357.vONjUmoVpt@nyoga.dubu.de>

Scaramouche wrote:
> open(INFILE, "infile.txt") or die "Error (infile): $!";
> my (%seen);
> while( <INFILE> )
>    {
>       ++$_ for @seen{/\d+/g};
>    }
> foreach (sort {$a == $b} keys %seen)

replace '==' by '<=>'.

>    {
>       print "$_ was a duplicate\n" if $seen{$_} > 1;
>    }
> close INFILE;
> 
> one last quick question though: if i wanted to print out those numbers
> that are NOT duplicates within the flat text file...
> ...would i simply change the '==' to '!=' within the foreach loop?

No, change the 'if' into 'unless'.


Ciao,
        Harald
-- 
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
++$sheep while !asleep();


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

Date: Sat, 05 Apr 2003 19:22:46 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: LWP post problem
Message-Id: <mbudash-1854CA.11224705042003@typhoon.sonic.net>

In article <bfe227db.0304050253.559dd87b@posting.google.com>,
 chacrint@hotmail.com (Chacrint Charinthorn) wrote:

> I tried to post using LWP but I got the following error:
> 
> 500 (Internal Server Error) Can't read entity body: Connection reset by peer
> 
> is it the problem with the problem I tried to post to?

what happens when you try to post to the url using a standard web form 
in a browser? what do you see?

hth-

-- 
Michael Budash


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

Date: Sat, 5 Apr 2003 22:11:08 +0100
From: Eddie Olsson <ewt@avajadi.org>
Subject: Re: open fails with filename starting with space
Message-Id: <20030405221108.71114667.ewt@avajadi.org>

On Sat, 29 Mar 2003 03:23:12 GMT
"J=FCrgen Exner" <jurgenex@hotmail.com> wrote:

> Vilmos Soti wrote:
> > I was writing a program which traversed a directory structure
> > (~/GNUstep), and I found that open couldn't open a filename with
> > a leading space. Is there a simple way (not sysopen) around it?
>=20
> Sure there is:
>     use File::Find;
> or
>     use File::Recurse;
>=20
> Then you don't have to write any directory traversing code at all.
>=20
> jue
>=20
>=20

 ...or simply use glob :)

/Avajadi


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

Date: Sat, 05 Apr 2003 21:54:01 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: open fails with filename starting with space
Message-Id: <ZfIja.14062$aQ3.8681@nwrddc02.gnilink.net>

Eddie Olsson wrote:
> On Sat, 29 Mar 2003 03:23:12 GMT
> "Jürgen Exner" <jurgenex@hotmail.com> wrote:
>
>> Vilmos Soti wrote:
>>> I was writing a program which traversed a directory structure
>>> (~/GNUstep), and I found that open couldn't open a filename with
>>> a leading space. Is there a simple way (not sysopen) around it?
>>
>> Sure there is:
>>     use File::Find;
>> or
>>     use File::Recurse;
>>
>> Then you don't have to write any directory traversing code at all.
>
> ...or simply use glob :)

Actually no because glob() doesn't traverse a directoy structure, it works
on a single directory only (or if you use a wildcard as a directory name
then on a single level of directories).

jue




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

Date: Sat, 05 Apr 2003 21:59:41 GMT
From: "Steven N. Hirsch" <shirsch@adelphia.net>
Subject: Re: perl's expat.so
Message-Id: <hlIja.1799$D31.502271@news1.news.adelphia.net>

Big and Blue wrote:
> Xiaojun Ping wrote:
> 
>>
>> There is no errors when I set LD_LIBRARY_PATH for libexpat.so before I 
>> run my perl program, but I always get the following errors when I set 
>> $ENV{LD_LIBRARY_PATH} to the same value inside my perl program, any 
>> idea ?
>>
>> ...perl5.6.0/sun4-solaris-thread-multi/auto/XML/Parser/Expat/Expat.so' 
>> for module XML::Parser::Expat: ld.so.1: /usr/bin/perl: fatal: 
>> libexpat.so.0: open failed: No such file or directory at 
>> ...perl-5.6.0/SunOS5.6/lib/5.6.0/sun4-solaris-thread-multi/DynaLoader.pm 
>> line 200, <F> line 5.
> 
> 
>    LD_LIBRARY_PATH is an environment variable that is used by the 
> dynamic loader which starts up the program.  Setting it as an 
> environment variabel within teh program (even within a BEGIN block) will 
> do you no good as it is already too late to be noticed.

Actually, the semantics vary by platform.  On AIX, for example, changes 
to LIBPATH do affect the current process.



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

Date: 5 Apr 2003 08:58:50 -0800
From: viijv@thedifferenZ.com (Vijoy Varghese)
Subject: PHP Code to PERL conversion...
Message-Id: <4c08aaff.0304050858.31858a24@posting.google.com>

Hello Group,

I have a website which runs using CGI/Perl. My website also have a php
discussion board called yabbse. I tweaked some code on that php script
so that my website have a single login for users. But now the yabbse
came with a new version of their board 1.5.1 today and this version
make use of a different 'password encryption' algorithm instead of the
crypt() in their old version.

The new php function is like this
// MD5 Encryption
function md5_hmac($data, $key)
{
	if (strlen($key) > 64)
		$key = pack('H*', md5($key));
	$key  = str_pad($key, 64, chr(0x00));

	$k_ipad = $key ^ str_repeat(chr(0x36), 64);
	$k_opad = $key ^ str_repeat(chr(0x5c), 64);

	return md5($k_opad . pack('H*', md5($k_ipad . $data)));
}

Can some one translate this to perl?

Thanking you in advance,

Regards
Vijoy Varghese~


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

Date: Sat, 5 Apr 2003 16:45:23 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: PHP Code to PERL conversion...
Message-Id: <slrnb8un43.6ca.tadmc@magna.augustmail.com>

Vijoy Varghese <viijv@thedifferenZ.com> wrote:

> The new php function is like this
> // MD5 Encryption
> function md5_hmac($data, $key)
> {
> 	if (strlen($key) > 64)
> 		$key = pack('H*', md5($key));
> 	$key  = str_pad($key, 64, chr(0x00));
> 
> 	$k_ipad = $key ^ str_repeat(chr(0x36), 64);
> 	$k_opad = $key ^ str_repeat(chr(0x5c), 64);
> 
> 	return md5($k_opad . pack('H*', md5($k_ipad . $data)));
> }
> 
> Can some one translate this to perl?


Yes.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 05 Apr 2003 16:16:09 GMT
From: "Josh Morrison" <Verbalx2@hotmail.com>
Subject: Re: Reformated Why won't this work.
Message-Id: <djDja.53032$0X.10716065@twister.columbus.rr.com>

I've only been coding in perl for now, 2 weeks.  I'm not good.  I'll be the
first one to admit to it.  And I've been working off what I have, which is
pretty bad I know.  I'm not claiming any superior knowledge here, that's
more than apparent.

I'm asking if I should change all of the OUTPUT to INPUT or just where you
pointed it out?

I've come across a load more problems with it and I'm pretty much on the
side of giving up on Perl and the script.  I guess with everyone's
professional comments, I'm way out of my league.





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

Date: Sat, 5 Apr 2003 08:26:21 -0600
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: regular expressions: newbie question
Message-Id: <MPG.18f8a3854432c38d989785@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <29c5bb08.0304041632.7a4dd054@posting.google.com>, MJL 
(mail@affordablemedicalsoftware.com) says...
> if I have a sentence:
> cats like to eat cat food with other cats.
> and I want to change it to:
> dogs like to eat dog food with other dogs.
> 
> why can't I do this?
> 
> while ((s/cat/dog/) );
> 
> or this:
> 
> while (defined (s/cat/dog/) );
> 
> or:
> 
> while ( (s/cat/dog/) == 1);
> 
> s/cat/dog/ by itself only replaces the first instance.
> 
> thanks!
> 
> -mjl
> 

You need to use the "/g" modifier to change *all* the occurrences of a 
particular substring.

$sentence = "cats like to eat cat food with other cats.";
$sentence =~ s/cat/dog/g;  # change all "cat" to "dog"

-- 
---------

Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com


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

Date: Sat, 05 Apr 2003 21:44:30 GMT
From: Steve Grazzini <grazz@nyc.rr.com>
Subject: Re: Stubbing FileHandle.pm
Message-Id: <27Ija.1391$py2.802@twister.nyc.rr.com>

Stephen Deken <google@awdang.com> wrote:
> O Font of Perl Wisdom,

{ wondering what you'd say in an oracle group }

> 
> I have a collection of modules that makes extensive use of
> FileHandle.pm.  I'm in the process of embedding these modules into
> another application written in C [...]
> 

Since you don't use any of the IO::* methods, why not just
get rid of the dependency altogether?

    open(my $fh, $filename) or die "open: '$filename': $!";

-- 
Steve


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

Date: Sat, 05 Apr 2003 18:13:20 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Substitution won't match for me
Message-Id: <41Fja.35074$B8.10562684@news4.srv.hcvlny.cv.net>


"Steve Ferson" <daNOSPAM_beano@hotmail.com> wrote in message
news:m1Aja.173$Kc3.26@newsfep3-gui.server.ntli.net...
> Just curious as to why this bit of code doesn't work. I've set myself
up a
> text file for holding messages of a message board.  It's really simple
but
> it's just for playing with.
>
> What  I want to do is convert all the newlines between <message> and
> </message> tags into <br/> tags for output as HTML.  I can't figure
out why
> the following substitution isn't working:
>
> $input =~ s/(<message>.*)\n(.*<\/message>)/$1<br\/>$2/gsx;
>
> can anyone help me?  It doesn't seem to be matching anything at all,
the
> code is output to HTML as a big long string. There are newlines in the
> source but not <br/> tags.
>
> Thanks,
> Steve
>
>

The reason your script does not work is documented (poorly)  in the last
paragraph of the s/PATTERN/REPLACEMENT/ section of perldoc perlop:

Occasionally, you can't use just a "/g" to get all the changes to occur
that you might want. Here are two common cases:

                # put commas in the right places in an integer
                1 while s/(\d)(\d\d\d)(?!\d)/$1,$2/g;
 .....

This approach seems to work.

use strict;
use warnings;
while (<DATA>){
 if(/<message>/../<\/message>/){
  s/\n/<br>/ if not /\/message>/;
 }
 print;
}
__END__
foo
foobar
foo<message>fifum
bar
bum
goo</message>
nomore

Good Luck,
Bill




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

Date: Sat, 5 Apr 2003 14:56:57 -0600
From: "Hiro Asari" <hiro@asari.net>
Subject: Re: Substitution won't match for me
Message-Id: <v8ugoobr59885a@corp.supernews.com>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1


"Steve Ferson" <daNOSPAM_beano@hotmail.com> wrote in message
news:m1Aja.173$Kc3.26@newsfep3-gui.server.ntli.net...
> Just curious as to why this bit of code doesn't work. I've set
myself up a
> text file for holding messages of a message board.  It's really
simple but
> it's just for playing with.
>
> What  I want to do is convert all the newlines between <message>
and
> </message> tags into <br/> tags for output as HTML.  I can't figure
out why
> the following substitution isn't working:
>
> $input =~ s/(<message>.*)\n(.*<\/message>)/$1<br\/>$2/gsx;
>
> can anyone help me?  It doesn't seem to be matching anything at
all, the
> code is output to HTML as a big long string. There are newlines in
the
> source but not <br/> tags.
>
> Thanks,
> Steve
>
>

Howdy.  I suspect the interaction between '.' right after <message>
in the regex and the /s modifier.  Remember that /s causes '.' to
match with '\n', so '(<message>.*)' is grabbing everything it can
until the last occurrence of '\n(.*</message>)' in $input.  I'm
guessing that you want the /m modifier instead of /s.  Also, /x
doesn't seem necessary.

HTH.

Hiro


-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - GPGOE 0.4.1

iD8DBQE+j0MZoXhPvmJPsrERAlASAKCWmUcENz1y8OOCpJEjOjsGInStVACglkaI
aG4IKi2NLcxBgpP4qs87/oY=
=y0Nz
-----END PGP SIGNATURE-----




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

Date: Sat, 5 Apr 2003 16:42:54 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Substitution won't match for me
Message-Id: <slrnb8umve.6ca.tadmc@magna.augustmail.com>

Hiro Asari <hiro@asari.net> wrote:
> "Steve Ferson" <daNOSPAM_beano@hotmail.com> wrote in message
> news:m1Aja.173$Kc3.26@newsfep3-gui.server.ntli.net...


>> $input =~ s/(<message>.*)\n(.*<\/message>)/$1<br\/>$2/gsx;

> I'm
> guessing that you want the /m modifier instead of /s.


That cannot possibly be the problem.

the /m modifier changes the meaning of the ^ and $ anchors, and
the OP's pattern does not use those anchors, so /m would be a no-op.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

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 4820
***************************************


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