[23211] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5432 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 3 11:05:47 2003

Date: Wed, 3 Sep 2003 08:05:11 -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           Wed, 3 Sep 2003     Volume: 10 Number: 5432

Today's topics:
        [newbie] how to get just the first value of a hash?? <guest1@deskpro192.internal.sanger.ac.uk>
    Re: [newbie] how to get just the first value of a hash? <someone@somewhere.com>
    Re: [newbie] how to get just the first value of a hash? <bigj@kamelfreund.de>
    Re: [newbie] how to get just the first value of a hash? <spam@thecouch.homeip.net>
    Re: [newbie] how to get just the first value of a hash? <bigj@kamelfreund.de>
    Re: [newbie] how to get just the first value of a hash? <nospam@please.com>
    Re: [newbie] how to get just the first value of a hash? <bharnish@technologist.com>
    Re: [newbie] how to get just the first value of a hash? <nospam@please.com>
        Brackets () in variable used for pattern match (Marcus Brody)
    Re: Brackets () in variable used for pattern match (Anno Siegel)
    Re: Brackets () in variable used for pattern match <t18_pilot@hotmail.spam.com>
    Re: Brackets () in variable used for pattern match <thens@NOSPAMti.com>
    Re: Brackets () in variable used for pattern match <thens@NOSPAMti.com>
    Re: Brackets () in variable used for pattern match (Marcus Brody)
    Re: Brackets () in variable used for pattern match <usenet@expires12.2003.tinita.de>
    Re: Help -- how to execute "computed Perl code" <nobull@mail.com>
    Re: IN SEARCH OF ELEGANT CODE: Setting a hash value to  (David Filmer)
        newbie question. how to assign an array to a hash table <guest1@deskpro192.internal.sanger.ac.uk>
    Re: newbie question. how to assign an array to a hash t (Anno Siegel)
    Re: newbie question. how to assign an array to a hash t (Tad McClellan)
    Re: newbie question. how to assign an array to a hash t <guest1@deskpro192.internal.sanger.ac.uk>
    Re: Reading a scalar line by line <abigail@abigail.nl>
    Re: Reading a scalar line by line (Sam Holden)
    Re: Reading a scalar line by line (Anno Siegel)
    Re: Redirecting via LWP <someone@somewhere.com>
        Replacing text - problem with $1 (Martin Kristensen)
    Re: Replacing text - problem with $1 (Anno Siegel)
    Re: Replacing text - problem with $1 (Villy Kruse)
    Re: Replacing text - problem with $1 (Martin Kristensen)
    Re: Replacing text - problem with $1 (Hunter Johnson)
    Re: Silly push tricks <abigail@abigail.nl>
        Strange OIDs returned for IBM 3584 v2c trap variables (John Ramsden)
    Re: View NG with Net::NNTP (Tom)
    Re: View NG with Net::NNTP <usenet@expires12.2003.tinita.de>
    Re: What ever happened to comp.lang.perl ? (Helgi Briem)
    Re: What ever happened to comp.lang.perl ? <flavell@mail.cern.ch>
    Re: Why qr// needs /o modifier, or bug in a documentati (Anno Siegel)
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 3 Sep 2003 14:52:22 +0100
From: Guest1 <guest1@deskpro192.internal.sanger.ac.uk>
Subject: [newbie] how to get just the first value of a hash??
Message-Id: <Pine.LNX.4.44.0309031441050.6919-100000@deskpro192.internal.sanger.ac.uk>


Thanks in advance
Pedro



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

Date: Wed, 3 Sep 2003 15:00:24 +0100
From: "Bigus" <someone@somewhere.com>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <bj4s5s$1774@newton.cc.rl.ac.uk>

There is no "first value of a hash". That is, a hash just consists of keys
and values. If you want the lowest value in a hash, assuming the values are
all numbers of course, then you could do it something like this:

@keys = sort {$hash{$a} <=> $hash{$b}} keys %hash;
print $hash{$keys[0]};

Bigus




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

Date: Wed, 03 Sep 2003 12:41:13 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <pan.2003.09.03.10.41.13.543985@kamelfreund.de>

Guest1 wrote at Wed, 03 Sep 2003 14:52:22 +0100:

You can't.
Hashs are unsorted, so there is no first key or value.


Greetings,
Janek


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

Date: Wed, 03 Sep 2003 10:06:23 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <Czm5b.57517$fQ3.1658516@weber.videotron.net>

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

Guest1 wrote:

In the future, please post your question in the body of your message, not just the subject.

> Thanks in advance
> Pedro

Unlike arrays, hashes are not an ordered list, therefore there's no concept of "first".

Think of a hash as a way to describe someone's face for example.  One property is eye colour, 
another is hair length, etc.  None of the properties are first or last or more important than the other.

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE/VfVieS99pGMif6wRAlP1AJ9hD06J8DtMctfiJWNjpD1HlJt9xwCgyFGx
jmMWbG/iGJMYyI/BXxfkkLw=
=+nrC
-----END PGP SIGNATURE-----



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

Date: Wed, 03 Sep 2003 12:43:41 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <pan.2003.09.03.10.43.41.401210@kamelfreund.de>

Guest1 wrote at Wed, 03 Sep 2003 14:52:22 +0100:

If you want to loop over the values of a hash,
you can either use the list of all values with

my $value = (values %hash)[0];

or iterate through with

while (my ($key, $value) = each %hash) {
   # do something with them
}

However, the returned value is in general not the same as the first value
you've written into the hash.


Greetings,
Janek


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

Date: Wed, 03 Sep 2003 14:14:26 GMT
From: Gunter Schelfhout <nospam@please.com>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <6Hm5b.17322$5E2.786568@phobos.telenet-ops.be>

Mina Naguib wrote:

> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
> 
> Guest1 wrote:
> 
> In the future, please post your question in the body of your message, not
> just the subject.
> 
>> Thanks in advance
>> Pedro
> 
> Unlike arrays, hashes are not an ordered list, therefore there's no
> concept of "first".
> 
> Think of a hash as a way to describe someone's face for example.  One
> property is eye colour,
> another is hair length, etc.  None of the properties are first or last or
> more important than the other.

Ack.

> -----BEGIN xxx SIGNATURE-----
> Version: GnuPG v1.2.1 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iD8DBQE/VfVieS99pGMif6wRAlP1AJ9hD06J8DtMctfiJWNjpD1HlJt9xwCgyFGx
> jmMWbG/iGJMYyI/BXxfkkLw=
> =+nrC
> -----END PGP SIGNATURE-----

Is this PGP-sig really nescessary on usenet? It's ugly like hell. And a lot
of work if you want to remove it on reply.
-- 
Blood, sweat & tears


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

Date: Wed, 03 Sep 2003 14:40:45 GMT
From: Brian Harnish <bharnish@technologist.com>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <pan.2003.09.03.14.41.06.220011@technologist.com>

On Wed, 03 Sep 2003 14:52:22 +0100, Guest1 wrote:

> 
> Thanks in advance
> Pedro

define first

 - Brian


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

Date: Wed, 03 Sep 2003 14:48:47 GMT
From: Gunter Schelfhout <nospam@please.com>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <pan.2003.09.03.14.49.06.941819@please.com>

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

On Wed, 03 Sep 2003 14:14:26 +0000, Gunter Schelfhout wrote:

> Mina Naguib wrote:
[snip...]
>> -----BEGIN xxx SIGNATURE-----
>> Version: GnuPG v1.2.1 (GNU/Linux)
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>> 
>> iD8DBQE/VfVieS99pGMif6wRAlP1AJ9hD06J8DtMctfiJWNjpD1HlJt9xwCgyFGx
>> jmMWbG/iGJMYyI/BXxfkkLw=
>> =+nrC
>> -----END PGP SIGNATURE-----
> 
> Is this PGP-sig really nescessary on usenet? It's ugly like hell. And a lot
> of work if you want to remove it on reply.

Yes, it is nescessary, it's the only way of telling who really sent the
message. And, the signatures are roughly the acceptable size for usenet
 .sig's.

 - Brian Harnish (bharnish@technologist.com)
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/Vf9RiK/rA3tCpFYRAnLaAJ9v8G2m44TI61KxVoCjmLwW6AOsugCgmzSv
BDUAWRPfYJqdoTUfOVdhEw0=
=oNJC
-----END PGP SIGNATURE-----



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

Date: 3 Sep 2003 02:09:57 -0700
From: dna@888.nu (Marcus Brody)
Subject: Brackets () in variable used for pattern match
Message-Id: <1ab76986.0309030109.2649f7db@posting.google.com>

Hi,

I'm new to perl and programming, so please please dont throw the
manual at me!!

Im trying to do a pattern match e.g.

if $foo =~ m/$bar/

However, on occasions $bar contains something like "HMGI(Y)", and the
brackets are intefering with the pattern match.  In all other
instances my script works.  I presume the brackets are being
extrapolated such that my pattern match *essentially* becomes:

if "HMGI(Y)" =~ m/HMGI(Y)/

Which clearly wont work, as the brackets are only used to capture Y in
the variable $1, and are otherwise "ignored".  Is there a way to
"escape" things in variables, even though I dont know whether they are
going to contain a bracket or not??


Thanks in advance


MB


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

Date: 3 Sep 2003 09:27:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Brackets () in variable used for pattern match
Message-Id: <bj4c5f$ntk$1@mamenchi.zrz.TU-Berlin.DE>

Marcus Brody <dna@888.nu> wrote in comp.lang.perl.misc:
> Hi,
> 
> I'm new to perl and programming, so please please dont throw the
> manual at me!!
> 
> Im trying to do a pattern match e.g.
> 
> if $foo =~ m/$bar/
> 
> However, on occasions $bar contains something like "HMGI(Y)", and the
> brackets are intefering with the pattern match.  In all other
> instances my script works.  I presume the brackets are being
> extrapolated such that my pattern match *essentially* becomes:
> 
> if "HMGI(Y)" =~ m/HMGI(Y)/
> 
> Which clearly wont work, as the brackets are only used to capture Y in
> the variable $1, and are otherwise "ignored".  Is there a way to
> "escape" things in variables, even though I dont know whether they are
> going to contain a bracket or not??

Look up quotemeta().  Use \Q.

Anno


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

Date: Wed, 03 Sep 2003 10:23:04 GMT
From: "William Hymen" <t18_pilot@hotmail.spam.com>
Subject: Re: Brackets () in variable used for pattern match
Message-Id: <cij5b.25799$Om1.8324@newsread2.news.atl.earthlink.net>

I just solved the problem yesterday for brackets. Funny you should ask.
I did this substitute before the match. It's not very elegant, but it works
by matching ANY character using the period in the same position
as the () charachters were.

$save=$bar;
$save =~ s|\(|\.|g;
$save =~ s|\)|\.|g;
if $foo =~ m/$save/



Hope This Helps -


"Marcus Brody" <dna@888.nu> wrote in message
news:1ab76986.0309030109.2649f7db@posting.google.com...
> Hi,
>
> I'm new to perl and programming, so please please dont throw the
> manual at me!!
>
> Im trying to do a pattern match e.g.
>
> if $foo =~ m/$bar/
>
> However, on occasions $bar contains something like "HMGI(Y)", and the
> brackets are intefering with the pattern match.  In all other
> instances my script works.  I presume the brackets are being
> extrapolated such that my pattern match *essentially* becomes:
>
> if "HMGI(Y)" =~ m/HMGI(Y)/
>
> Which clearly wont work, as the brackets are only used to capture Y in
> the variable $1, and are otherwise "ignored".  Is there a way to
> "escape" things in variables, even though I dont know whether they are
> going to contain a bracket or not??
>
>
> Thanks in advance
>
>
> MB




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

Date: Wed, 3 Sep 2003 17:07:55 +0530
From: Thens <thens@NOSPAMti.com>
Subject: Re: Brackets () in variable used for pattern match
Message-Id: <20030903170755.1e0161e6.thens@NOSPAMti.com>

On 3 Sep 2003 02:09:57 -0700
dna@888.nu (Marcus Brody) wrote:

>Hi,
>
>I'm new to perl and programming, so please please dont throw the
>manual at me!!

  You will remain a newbie, if you dont develop a liking for the manual
;-).

  Manual is the best source of reference, what more it is available in
your hard disk. What are you waiting for. 

perldoc -f <fucntion> 
perldoc -q <keyword>  # faq search
perldoc perldoc       # to know about the manual
perldoc perldata      # perl data structures 
perldoc perlre        # Regular expressions
perldoc perlref       # references
- more- 

  Have fun !!

Regards,
Thens.





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

Date: Wed, 3 Sep 2003 17:04:04 +0530
From: Thens <thens@NOSPAMti.com>
Subject: Re: Brackets () in variable used for pattern match
Message-Id: <20030903170404.6f5b26e3.thens@NOSPAMti.com>

"William Hymen" <t18_pilot@hotmail.spam.com> wrote:

>I just solved the problem yesterday for brackets. Funny you should ask.
>I did this substitute before the match. It's not very elegant, but it works
>by matching ANY character using the period in the same position
>as the () charachters were.
>
> [ snipped a bad example ]
>
  
  Please do not top post. Quote only what is needed and post  your reply
at the bottom of the quote. 

  Back to the problem, your solution is not generic. When perl provides
you facilities to Quote the meta characters in a regex, why reinvent the
wheel that too badly. use \Q to quote. 

perl -e 'print "\QABCD(Y)"'    

   to see what happens when you use \Q. 

Regards, 
Thens.






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

Date: 3 Sep 2003 06:31:44 -0700
From: dna@888.nu (Marcus Brody)
Subject: Re: Brackets () in variable used for pattern match
Message-Id: <1ab76986.0309030531.25fce441@posting.google.com>

>I just solved the problem yesterday for brackets. Funny you should ask.
>I did this substitute before the match. It's not very elegant, but it works
>by matching ANY character using the period in the same position
>as the () charachters were.
>
>$save=$bar;
>$save =~ s|\(|\.|g;
>$save =~ s|\)|\.|g;
>if $foo =~ m/$save/


Hey

Just came to pretty much the same conclusion myself ;-)
instead, I quoted the offending characters rather than exchanging them:

e.g.
$save =~ s|\(|\\\(|g;
etc.

(with the "\\" equally an escaped "\" and the "\(" equalling an escaped "(" )

This is pretty much the same as quotemeta, so I shall use that instead :-)

Thanks peoples

MB


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

Date: 3 Sep 2003 13:58:13 GMT
From: Tina Mueller <usenet@expires12.2003.tinita.de>
Subject: Re: Brackets () in variable used for pattern match
Message-Id: <bj4s1l$dqr73$2@ID-24002.news.uni-berlin.de>

Marcus Brody wrote:
> e.g.
> $save =~ s|\(|\\\(|g;
> etc.

> (with the "\\" equally an escaped "\" and the "\(" equalling an escaped "(" )

> This is pretty much the same as quotemeta, so I shall use that instead :-)

pretty much the same except that quotemeta also takes care of
a lot more characters like ?, ., [, ], +, *, . and so on.
so, yes, please use quotemeta() instead =)

-- 
http://www.tinita.de/     \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/   \     / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/   \    \ _,_\ __/\ __/_| /__/ perception
- the above mail address expires end of december 2003 -


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

Date: 02 Sep 2003 23:36:37 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Help -- how to execute "computed Perl code"
Message-Id: <u965kab7a0.fsf@wcl-l.bham.ac.uk>

google.deller@smsail.com (Steve D) writes:

>    my $code = sub { eval "$code_text" } ; # Just need eval to make it

>    $code->() ;

That is pointless.

May as well just:

   eval $code_text;

I suspect what you were tring to do was:

my $code = eval "sub { $code_text }";

Apply standard admionishments about being damn sure that $code_text
can never contain any text from any source that would not be trusted
to run their own scripts under the current user ID.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 3 Sep 2003 00:57:23 -0700
From: IneverReadAnythingSentToMe@hotmail.com (David Filmer)
Subject: Re: IN SEARCH OF ELEGANT CODE: Setting a hash value to a chomp'ed thing
Message-Id: <e4c916dd.0309022357.56493908@posting.google.com>

Bart Lateur <bart.lateur@pandora.be> wrote in message news:<d9takvo352aosmhu5glc4n0itcr56kotsf@4ax.com>...

> 	chomp($hash{key} = `which ps`);

Yes, thanks, Bart, but I already knew that worked (see the PS in my
original post).  I have a reason for wanting to use the
%hash=(key=>value) syntax (rather than %hash{key}=value syntax).

Thanks especially to Tassilo and Randall for (again) showing me new
and wonderful ways to use (if not to abuse) Perl. And, thanks Dave
Saville, for asking Tassilo to further elaborate on his ingenious
answer; his further explanation proved most enlightening.


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

Date: Wed, 3 Sep 2003 10:28:05 +0100
From: Guest1 <guest1@deskpro192.internal.sanger.ac.uk>
Subject: newbie question. how to assign an array to a hash table?
Message-Id: <Pine.LNX.4.44.0309031017290.6552-100000@deskpro192.internal.sanger.ac.uk>


Hi,

I have something like:

 $value = 'A' 'C' 'G';

and I would like store this value on a hash table.

    my @value = split(' ',$value);
    print "=>\t@value[1]\n"; # print: =>    C;
    ($splitted_hap{$key}) = @value;

while trying to print the values:

print "\n";

while ( (my $key, my @value) = each(%splitted_hap) ) {
    print "$key\t$value[0]\n";
    print "$key\t$value[1]\n";
}


I get:


first	A
first	
second	C
second	
third	A
third	

why the values are not been stored on value[1]

what I am doing wrong?


Thanks for your help
Pedro




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

Date: 3 Sep 2003 09:53:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: newbie question. how to assign an array to a hash table?
Message-Id: <bj4dlt$ntk$3@mamenchi.zrz.TU-Berlin.DE>

Guest1  <guest1@deskpro192.internal.sanger.ac.uk> wrote in comp.lang.perl.misc:
> 
> Hi,
> 
> I have something like:
> 
>  $value = 'A' 'C' 'G';

This doesn't compile.  It can't be your real code.

> and I would like store this value on a hash table.
> 
>     my @value = split(' ',$value);
>     print "=>\t@value[1]\n"; # print: =>    C;
>     ($splitted_hap{$key}) = @value;
> 
> while trying to print the values:
> 
> print "\n";
> 
> while ( (my $key, my @value) = each(%splitted_hap) ) {
>     print "$key\t$value[0]\n";
>     print "$key\t$value[1]\n";
> }
> 
> 
> I get:
> 
> 
> first	A

No you don't get that, not with the code you posted.  Even ignoring
the invalid syntax in the first line (and who knows what else), the
string "first" appears nowhere in your program.  Please show your
real code.

[...]

Anno


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

Date: Wed, 3 Sep 2003 07:51:13 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: newbie question. how to assign an array to a hash table?
Message-Id: <slrnblbou1.3q3.tadmc@magna.augustmail.com>

Guest1 <guest1@deskpro192.internal.sanger.ac.uk> wrote:

> I have something like:


"something like" is not good enough for us to be able to help you.

We need _real Perl code_ in order to determine what is wrong with the code.


>  $value = 'A' 'C' 'G';


That is not Perl code.

There are many modules for processing DNA sequences, have you
seen if any of those wheels will roll your cart?


> and I would like store this value on a hash table.
> 
>     my @value = split(' ',$value);
>     print "=>\t@value[1]\n"; # print: =>    C;
                 ^
                 ^

You should always enable warnings when developing Perl code!


>     ($splitted_hap{$key}) = @value;


This will store only the 'A' in the hash.

Don't you want 'C' and 'G' in there somewhere too?

You will need to understand references if you want to do that.


> while trying to print the values:
> 
> print "\n";
> 
> while ( (my $key, my @value) = each(%splitted_hap) ) {


The hash values are not arrays, @value can never have more
than one element in it...


>     print "$key\t$value[0]\n";
>     print "$key\t$value[1]\n";


 ... so $value[1] will never be defined.


> }
> 
> 
> I get:
> 
> 
> first	A
> first	


Your program cannot possibly make that output.

Many people will not volunteer to help you if you lie to them...


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


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

Date: Wed, 3 Sep 2003 14:38:27 +0100
From: Guest1 <guest1@deskpro192.internal.sanger.ac.uk>
Subject: Re: newbie question. how to assign an array to a hash table?
Message-Id: <Pine.LNX.4.44.0309031435010.6914-100000@deskpro192.internal.sanger.ac.uk>


thanks guys for your help.

The fixed code is:

my %hap =(
   "first"  => 'a c g t',
   "second" => 'c g ? t',
   "third"  => 'a g t a',
);

foreach my $key (keys %hap) {
    my @values = split(' ',$hap{$key});
    $splitted_hap{$key} = \@values;
}

now works fine!

I didn't know how to pass the splitted String into the array.

Thanks
Pedro


On Wed, 3 Sep 2003, Tad McClellan wrote:

> Guest1 <guest1@deskpro192.internal.sanger.ac.uk> wrote:
> 
> > I have something like:
> 
> 
> "something like" is not good enough for us to be able to help you.
> 
> We need _real Perl code_ in order to determine what is wrong with the code.
> 
> 
> >  $value = 'A' 'C' 'G';
> 
> 
> That is not Perl code.
> 
> There are many modules for processing DNA sequences, have you
> seen if any of those wheels will roll your cart?
> 
> 
> > and I would like store this value on a hash table.
> > 
> >     my @value = split(' ',$value);
> >     print "=>\t@value[1]\n"; # print: =>    C;
>                  ^
>                  ^
> 
> You should always enable warnings when developing Perl code!
> 
> 
> >     ($splitted_hap{$key}) = @value;
> 
> 
> This will store only the 'A' in the hash.
> 
> Don't you want 'C' and 'G' in there somewhere too?
> 
> You will need to understand references if you want to do that.
> 
> 
> > while trying to print the values:
> > 
> > print "\n";
> > 
> > while ( (my $key, my @value) = each(%splitted_hap) ) {
> 
> 
> The hash values are not arrays, @value can never have more
> than one element in it...
> 
> 
> >     print "$key\t$value[0]\n";
> >     print "$key\t$value[1]\n";
> 
> 
> ... so $value[1] will never be defined.
> 
> 
> > }
> > 
> > 
> > I get:
> > 
> > 
> > first	A
> > first	
> 
> 
> Your program cannot possibly make that output.
> 
> Many people will not volunteer to help you if you lie to them...
> 
> 
> 



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

Date: 03 Sep 2003 14:27:02 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Reading a scalar line by line
Message-Id: <slrnblbuhl.lgd.abigail@alexandra.abigail.nl>

Tore Aursand (tore@aursand.no) wrote on MMMDCLIV September MCMXCIII in
<URL:news:8O35b.19363$os2.267274@news2.e.nsc.no>:
&&  AcCeSsDeNiEd wrote:
&& > Hi, does anyone know how I would do this?
&&  
&&  Do what?
&&  
&& > something like:
&&  
&&  That's not good enough.  Tell us excactly _what_ you want to do, and 
&&  we'll help you.  Lucky you, your subject told us a little.
&&  
&& > while ($string)
&& > 
&& > 	print _$
&& > }
&&  
&&  No wonder.  Try splitting your $string on line breaks (if that _is_ what 
&&  you want to do);
&&  
&&     while ( split(/\n/, $string) ) {
&&         print $_;
&&     }


That will never terminate unless $string was empty.
Perhaps you meant:

    for (split /\n/ => $string) {
        ...
    }

That would work, but it takes potentially a lot of memory if $string
is huge. 

I would do:

    while ($string =~ /(.*)/g) {
        print $1;
    }

Abigail
-- 
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
                                      print } sub __PACKAGE__ { &
                                      print (     __PACKAGE__)} &
                                                  __PACKAGE__
                                            (                )


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

Date: 3 Sep 2003 14:48:37 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Reading a scalar line by line
Message-Id: <slrnblbvq5.gt3.sholden@flexal.cs.usyd.edu.au>

On 03 Sep 2003 14:27:02 GMT, Abigail <abigail@abigail.nl> wrote:
[snip a while instead of a for...]

> 
> That will never terminate unless $string was empty.
> Perhaps you meant:
> 
>     for (split /\n/ => $string) {
>         ...
>     }
> 
> That would work, but it takes potentially a lot of memory if $string
> is huge. 
> 
> I would do:
> 
>     while ($string =~ /(.*)/g) {
>         print $1;
>     }

The body of the loop will get slightly different data then the split version.

Since (.*) will match the empty string between the text of the line and
the newline character (well something like that anyway, extra empty values
get passed to the loop body  in $1 anyway).

-- 
Sam Holden



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

Date: 3 Sep 2003 15:04:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Reading a scalar line by line
Message-Id: <bj4vua$6th$1@mamenchi.zrz.TU-Berlin.DE>

Sam Holden <sholden@cs.usyd.edu.au> wrote in comp.lang.perl.misc:
> On 03 Sep 2003 14:27:02 GMT, Abigail <abigail@abigail.nl> wrote:
> [snip a while instead of a for...]
> 
> > 
> > That will never terminate unless $string was empty.
> > Perhaps you meant:
> > 
> >     for (split /\n/ => $string) {
> >         ...
> >     }
> > 
> > That would work, but it takes potentially a lot of memory if $string
> > is huge. 
> > 
> > I would do:
> > 
> >     while ($string =~ /(.*)/g) {
> >         print $1;
> >     }
> 
> The body of the loop will get slightly different data then the split version.
> 
> Since (.*) will match the empty string between the text of the line and
> the newline character (well something like that anyway, extra empty values
> get passed to the loop body  in $1 anyway).

Here's a variant that avoids this:

    print "$1\n" while $multi =~ /(^.*)/mg;

Anno


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

Date: Wed, 3 Sep 2003 09:12:29 +0100
From: "Bigus" <someone@somewhere.com>
Subject: Re: Redirecting via LWP
Message-Id: <bj47pd$k5o@newton.cc.rl.ac.uk>

"Michael Budash" <mbudash@sonic.net> wrote in message
news:mbudash-1164EB.23580201092003@typhoon.sonic.net...

> look into the <base href="..."> html tag, then do this:
>
> $response = $resp->content;
> $response =~
>    s{(</head>)}{<base href="http://mydomain.com/files/$listname/">$1}i;
>
> it's what i do and it works like a champ.

Thanks.. this does work and is what I've employed for now, although it is a
browser dependant solution. Having said that, I checked a compatibility
chart and it seems <base href..> is supported by pretty much every browser
since the dawn of time :)

Regards
Bigus




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

Date: 3 Sep 2003 02:16:58 -0700
From: kr00z3r@yahoo.com (Martin Kristensen)
Subject: Replacing text - problem with $1
Message-Id: <a18651a5.0309030116.3ffa60ac@posting.google.com>

I'm trying to replace some text in some txt-files with a perl call
like this...

perl -pi -e "s/brad(.+?)bill/brian$1bob/gm;" *.txt

This should replace "brad123bill" by "brian123bob" - but instead I
just get "brianbob". What's wrong? Probably something with the $1
variable, but what?

Regards
Martin


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

Date: 3 Sep 2003 09:44:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Replacing text - problem with $1
Message-Id: <bj4d6l$ntk$2@mamenchi.zrz.TU-Berlin.DE>

Martin Kristensen <kr00z3r@yahoo.com> wrote in comp.lang.perl.misc:
> I'm trying to replace some text in some txt-files with a perl call
> like this...
> 
> perl -pi -e "s/brad(.+?)bill/brian$1bob/gm;" *.txt
> 
> This should replace "brad123bill" by "brian123bob" - but instead I
> just get "brianbob". What's wrong? Probably something with the $1
> variable, but what?

Nothing is wrong with the regex, except for the /m modifier, which does
nothing.

Anno


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

Date: 03 Sep 2003 11:56:28 GMT
From: vek@station02.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: Replacing text - problem with $1
Message-Id: <slrnblblnc.4mo.vek@station02.ohout.pharmapartners.nl>

On 3 Sep 2003 02:16:58 -0700,
    Martin Kristensen <kr00z3r@yahoo.com> wrote:


>I'm trying to replace some text in some txt-files with a perl call
>like this...
>
>perl -pi -e "s/brad(.+?)bill/brian$1bob/gm;" *.txt
>
>This should replace "brad123bill" by "brian123bob" - but instead I
>just get "brianbob". What's wrong? Probably something with the $1
>variable, but what?
>

Your shell ate the $1 parameter.  



Villy


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

Date: 3 Sep 2003 06:07:31 -0700
From: kr00z3r@yahoo.com (Martin Kristensen)
Subject: Re: Replacing text - problem with $1
Message-Id: <a18651a5.0309030507.2b4593a8@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<bj4d6l$ntk$2@mamenchi.zrz.TU-Berlin.DE>...
> Martin Kristensen <kr00z3r@yahoo.com> wrote in comp.lang.perl.misc:
> > I'm trying to replace some text in some txt-files with a perl call
> > like this...
> > 
> > perl -pi -e "s/brad(.+?)bill/brian$1bob/gm;" *.txt
> > 
> > This should replace "brad123bill" by "brian123bob" - but instead I
> > just get "brianbob". What's wrong? Probably something with the $1
> > variable, but what?
> 
> Nothing is wrong with the regex, except for the /m modifier, which does
> nothing.

I solved the problem by replacing " by ' so now it works perfectly for
some reason. :)

Martin


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

Date: 3 Sep 2003 06:31:28 -0700
From: hunter@hunterandlori.com (Hunter Johnson)
Subject: Re: Replacing text - problem with $1
Message-Id: <19afcf24.0309030531.261a1e56@posting.google.com>

kr00z3r@yahoo.com (Martin Kristensen) wrote in message news:<a18651a5.0309030116.3ffa60ac@posting.google.com>...
> I'm trying to replace some text in some txt-files with a perl call
> like this...
> 
> perl -pi -e "s/brad(.+?)bill/brian$1bob/gm;" *.txt
> 
> This should replace "brad123bill" by "brian123bob" - but instead I
> just get "brianbob". What's wrong? Probably something with the $1
> variable, but what?

Regexp is fine.  By the time it gets to perl, though, the s command
looks like this:

s/brad(.+?)bill/brianbob/gm

Your shell has replaced $1 with its value (nothing) before passing it
to perl.  Replacing the double quotes with single quotes should work. 
If not, time to dig out the shell's documentation.

Hunter
--
http://www.hunterandlori.com


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

Date: 03 Sep 2003 12:36:27 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Silly push tricks
Message-Id: <slrnblbo2a.po2.abigail@alexandra.abigail.nl>

Bill Smith (wksmith@optonline.net) wrote on MMMDCLIV September MCMXCIII
in <URL:news:eH25b.118653$yg.34091232@news4.srv.hcvlny.cv.net>:
:}  
:}  "Shawn Corey" <shawn@magma.ca> wrote in message
:}  news:3l6dnaqT0_d6OsmiU-KYvg@magma.ca...
:}  --snip--
:} > map{&test($_)?push@sheep,$_:push@goats,$_}@bleats;
:} >
:}  I think that it is poor style to use 'map' when the return value is not
:}  used.

Poor style? Why? Return values of print and assignment are usually not
used either, but noone considers that poor style.

The fact that map builds and discards a list when it's used in void
context is a bug in *perl*. It's not poor style of the Perl programmer;
the fault lies with the perl programmers.

But noone has found it seriously enough to provide a patch. For years,
a whole chorus on people in this newsgroup chant "poor style" whenever
someone uses map in void context. But none of those sheep has ever 
bothered sending a patch to p5p.



Abigail
-- 
perl -we'$;=$";$;{Just=>another=>Perl=>Hacker=>}=$/;print%;'


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

Date: 3 Sep 2003 07:28:44 -0700
From: john_ramsden@sagitta-ps.com (John Ramsden)
Subject: Strange OIDs returned for IBM 3584 v2c trap variables
Message-Id: <d27434e.0309030628.55ae32d4@posting.google.com>

I am using the Perl Convert::BER module to decode traps, and it works
fine with both v1 and v2c traps for several MIBs and even caters for
OID indexes.

But in traps received from an IBM 3584, the trap variables' OIDs
end with '.0.0' (except, in v2c traps, the first two standard
variables namely sysUpTime.0 and snmpTrapOID.0) when these
should end with '.1.0'.

When my code replaces the '.0.0' strings by '.1.0' (and then strips
the trailing '.0' as usual) I can locate the variable name from the
'smidump' Perl output for the MIB file ('smidump' being part of the
excellent and indispensable libsmi open-source package for parsing
MIBS - see http://www.ibr.cs.tu-bs.de/projects/libsmi/)

But I'm wondering if this is some peculiarity or bug specific to
the IBM MIB or yet another weird quirk of SNMP itself. Does an OID
with more than one trailing zero have any special significance,
or is there a standard way of dealing with it?

Diagnostic information follows for any would-be SNMP Sherlocks
out there ;-)

(I'd concede this post isn't primarily about Perl. But I've copied
it to comp.lang.perl.misc for possible general interest to anyone
using Perl to deal with SNMP. The bottom line is that with libsmi
and Convert::BER the world, or SNMP world anyway, is your oyster!)


Cheers

John R Ramsden (john_ramsden@sagitta-ps.com)



The following is a cut-down extract from ibm3584v2c.mib:

   -- Machine type, model number, library serial number ID
   ibm3584MIBGroupMTMNLSN OBJECT IDENTIFIER
        ::= { ibm3584MIBObjects 11 }

      :::

   ibm3584MIBObjectsMTMNLSN OBJECT-TYPE
           SYNTAX DisplayString (SIZE (1..16))
           MAX-ACCESS read-only
           STATUS current
           DESCRIPTION "This is the machine type associated with the trap."
          ::= { ibm3584MIBGroupMTMNLSN 1 }

     :::

   ibm3584Trap408 NOTIFICATION-TYPE
           OBJECTS {
    ibm3584MIBObjectsMTMNLSN,
    ibm3584MIBObjectsLL,
      :::
                 }

The following is an extract from the 'smidump' Perl output for the
same objects:

        {
            "name" => "ibm3584MIBGroupMTMNLSN",
            "type" => "node",
            "module" => "IBM-3584-MIB",
            "oid" => "1.3.6.1.4.1.2.6.182.1.2.11",
        }, # ibm3584MIBGroupMTMNLSN
        {
            "name" => "ibm3584MIBObjectsMTMNLSN",
            "type" => "scalar",
            "module" => "IBM-3584-MIB",
            "oid" => "1.3.6.1.4.1.2.6.182.1.2.11.1",
            "status" => "current",
            "description" =>
                'This is the machine type associated with the trap.',
            "syntax" => {
                "type" => 
                {
                    "basetype" => "OctetString",
                    "parent" => {
                        "module" => "SNMPv2-TC",
                        "name" => "DisplayString",
                    },
                    "range" => {
                        "min" => "1",
                        "max" => "16"
                    },
                },
            },
            "access" => "readonly",
        }, # ibm3584MIBObjectsMTMNLSN

Finally the following is a Convert::BER dump of the v2c trap
variables in which the rogue [?] OIDs with trailing '.0.0' can
be seen:

   0000 A7  284: CONTEXT [7]
    {
   0004 02    1:   INTEGER
    = 0
   0007 02    1:   INTEGER
    = 0
   000A 02    1:   INTEGER
    = 0
   000D 30  271:   SEQUENCE
    {
   0011 30   16:     SEQUENCE
    {
   0015 06    8:       OBJECT ID
    = 1.3.6.1.2.1.1.3.0
   001F 43    4:       APPLICATION [3]

   0020        :         03 34 80 66 __ __ __ __ __ __ __ __ __ __ __ __ .4.f
   0025        :     }
   0025 30   28:     SEQUENCE
    {
   0029 06   10:       OBJECT ID
    = 1.3.6.1.6.3.1.1.4.3.0
   0035 06   14:       OBJECT ID
    = 1.3.6.1.4.1.2.6.182.1.0.408.0
   0045        :     }
   0045 30   34:     SEQUENCE
    {
   0049 06   14:       OBJECT ID
    = 1.3.6.1.4.1.2.6.182.1.2.11.0.0
   0059 04   16:       STRING
    = '3584 L32 1311031'
   006B        :     }
   006B 30   26:     SEQUENCE
    {
   006F 06   14:       OBJECT ID
    = 1.3.6.1.4.1.2.6.182.1.2.21.0.0
   007F 04    8:       STRING
    = '04 55 66'
   0089        :     }
   0089 30   23:     SEQUENCE
    {
   008D 06   14:       OBJECT ID
    = 1.3.6.1.4.1.2.6.182.1.2.31.0.0
   009D 04    5:       STRING
    = '77 88'
   00A4        :     }
   00A4 30   20:     SEQUENCE
    {
   00A8 06   14:       OBJECT ID
    = 1.3.6.1.4.1.2.6.182.1.2.41.0.0
   00B8 04    2:       STRING
    = '02'
   00BC        :     }
   00BC 30   22:     SEQUENCE
    {
   00C0 06   14:       OBJECT ID
    = 1.3.6.1.4.1.2.6.182.1.2.51.0.0
   00D0 04    4:       STRING
    = '0000'
   00D6        :     }
   00D6 30   23:     SEQUENCE
    {
   00DA 06   14:       OBJECT ID
    = 1.3.6.1.4.1.2.6.182.1.2.61.0.0
   00EA 04    5:       STRING
    = '09 08'
   00F1        :     }
   00F1 30   43:     SEQUENCE
    {
   00F5 06   14:       OBJECT ID
    = 1.3.6.1.4.1.2.6.182.1.2.71.0.0
   0105 04   25:       STRING
    = 'This is a test SNMP trap.'
   0120        :     }
   0120        :   }
   0120        : }


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

Date: 3 Sep 2003 05:13:18 -0700
From: tom@ztml.com (Tom)
Subject: Re: View NG with Net::NNTP
Message-Id: <59b4279a.0309030413.2046b2db@posting.google.com>

csdude@hotmail.com (Mike) wrote in message news:<46cdc619.0309022039.723ec45a@posting.google.com>...
> I have a client that would really benefit from allowing his visitors
> to read a specific newsgroup on his site.
> 
> Specifically, I want to be able to show the most recent, say, 20
> article headers from a specific newsgroup, then when the visitor
> selects an article then they can read the body. Then, I want to give
> the visitor an option to post to that NG.

You can use Net::NNTP to do the above. I'm currently developing a
feature similar to what you described into a template system that I
developed called TML (Template Markup Language). You can view the
sample outputs by going to
http://ztml.com/cgi-bin/demo/mb.pl?disp+perl+NGtopics.admin.dsp

Tom


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

Date: 3 Sep 2003 13:27:45 GMT
From: Tina Mueller <usenet@expires12.2003.tinita.de>
Subject: Re: View NG with Net::NNTP
Message-Id: <bj4q8h$dqr73$1@ID-24002.news.uni-berlin.de>

Mike wrote:

> I have a client that would really benefit from allowing his visitors
> to read a specific newsgroup on his site.

just a suggestion; i developed a news-to-web application a
year ago, and i stored the message-ids in a tree-structure,
so that the script doesn't have to read all message-ids and build
the structure every time it is called. i used the newnews()-method
to get all new messages since a given timestamp. if that is
necessary in your case, depends, of course, on the size of the
newsgroup and on the number of requests to that script.

> I've been looking through
> some modules, and even though a lot of the standard modules mention
> this, I haven't been able to find any actual references so I think I
> might be misunderstanding the wording in the modules.

but you have read perldoc Net::NNTP? there are methods to
set the group (group ()), to get the ids (list() and next()), and
to get an article (article()), the header (head()) and body (body()).
they are all documented in Net::NNTP.

hth, tina
-- 
http://www.tinita.de/     \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/   \     / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/   \    \ _,_\ __/\ __/_| /__/ perception
- the above mail address expires end of december 2003 -


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

Date: Wed, 03 Sep 2003 11:55:18 GMT
From: f_baggins80@hotmail.com (Helgi Briem)
Subject: Re: What ever happened to comp.lang.perl ?
Message-Id: <3f55d605.171777583@News.CIS.DFN.DE>

On Wed, 3 Sep 2003 00:47:04 -0500, tadmc@augustmail.com (Tad
McClellan) wrote:

>
>Trent Curry, Islaw, krakle, MJ Owens, Cpt Fredo,  
>Manny Wilco, Robin Givens and a cast of thousands wrote:
>
>> been around, yet they were expected to 
>know all the rules. I know some jsut
>                                                        ^^^^

This joker must be a glutton for punishment.

Why does he keep coming back?

What does he want?

Strangely, if we just killfiled everybody who mistypes
just j-s-u-t, we'd probably get rid of this moron forever
at only a tiny cost.  It might be worth it.
--
Helgi Briem  hbriem AT simnet DOT is

Excuses the munged address.  My last
e-mail address was killed by spammers.


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

Date: Wed, 3 Sep 2003 14:27:13 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: What ever happened to comp.lang.perl ?
Message-Id: <Pine.LNX.4.53.0309031426140.30136@lxplus087.cern.ch>

On Wed, Sep 3, Helgi Briem inscribed on the eternal scroll:

> Why does he keep coming back?

Perhaps he's the mysterious Frank ?

SCNR.


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

Date: 3 Sep 2003 08:45:31 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why qr// needs /o modifier, or bug in a documentation.
Message-Id: <bj49nb$maj$1@mamenchi.zrz.TU-Berlin.DE>

ddtl  <this.is.invalid@yahoo.com> wrote in comp.lang.perl.misc:
> 
> Hello everybody,
> 
> I have some difficulty to understand why does qr// operator needs 
> 'o' modifier. There seems to be a disagreement between perlop manpage
> and "Programming Perl" (3rd edition - i will use PP for short from now 
> on).

The qr// operator doesn't need the /o modifier, you must have misunder-
stood what the documentation is saying.  The relation is that qr// can
be used to achieve what /o would be needed for without it.

[snip]

Anno


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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