[29198] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 442 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 17 14:09:55 2007

Date: Thu, 17 May 2007 11:09:06 -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           Thu, 17 May 2007     Volume: 11 Number: 442

Today's topics:
    Re: Correlating Data from same .csv, line by line <bik.mido@tiscalinet.it>
    Re: encoding problem on Tk entry widget <ch.l.ngre@online.de>
    Re: How to handling string contains single quote and do <vikrant.kansal@gmail.com>
        Modifying $_ in "map", with an array containing a gap.. <gypark@gmail.com>
    Re: Modifying $_ in "map", with an array containing a g <bik.mido@tiscalinet.it>
    Re: Modifying $_ in "map", with an array containing a g <wahab-mail@gmx.de>
    Re: Modifying $_ in "map", with an array containing a g <m@rtij.nl.invlalid>
    Re: Modifying $_ in "map", with an array containing a g <bik.mido@tiscalinet.it>
    Re: Modifying $_ in "map", with an array containing a g <ron.hartikka@gmail.com>
    Re: Modifying $_ in "map", with an array containing a g <glennj@ncf.ca>
    Re: Modifying $_ in "map", with an array containing a g <wahab-mail@gmx.de>
    Re: Modifying $_ in "map", with an array containing a g <wahab-mail@gmx.de>
    Re: Modifying $_ in "map", with an array containing a g xhoster@gmail.com
    Re: Modifying $_ in "map", with an array containing a g <yankeeinexile@gmail.com>
    Re: Modifying $_ in "map", with an array containing a g <nobull67@gmail.com>
    Re: Modifying $_ in "map", with an array containing a g <bik.mido@tiscalinet.it>
        Problem with perl group capture. <cooldudevamsee@gmail.com>
    Re: Problem with perl group capture. <spamtrap@dot-app.org>
    Re: Problem with perl group capture. <bik.mido@tiscalinet.it>
    Re: regular expressions? <m@rtij.nl.invlalid>
    Re: regular expressions? <nobull67@gmail.com>
    Re: Simple Regular Expression Help <dalessio@motorola.NOSPAM.com>
        Sorting Hash by Value and Key vunet.us@gmail.com
    Re: Sorting Hash by Value and Key <bik.mido@tiscalinet.it>
    Re: Sorting Hash by Value and Key <cwilbur@chromatico.net>
    Re: Sorting Hash by Value and Key <wahab-mail@gmx.de>
    Re: Test harness for scripts? <sisyphus1@nomail.afraid.org>
        Watch Television online for free. shane.buggins41@ntlworld.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 17 May 2007 10:21:44 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Correlating Data from same .csv, line by line
Message-Id: <l24o43prsi16b6j8j93a9tgj5ivbl6itsg@4ax.com>

On 16 May 2007 21:47:15 -0700, gskallur@gmail.com wrote:

>saved from url=(0022)http://internet.e-mail -->
[snip 490 more lines of code seemingly containing no Perl at all]

Huh?!?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Thu, 17 May 2007 10:45:09 +0200
From: Ch Lamprecht <ch.l.ngre@online.de>
Subject: Re: encoding problem on Tk entry widget
Message-Id: <f2h4mi$j2f$2@online.de>

filippo wrote:
> I have a strange problem, probably due to encoding:
> 
> my database tables (postgresql) have Latin9 encoding and stores
> italian names (a e i o u with accent). I can retrieve these names and
> load into entry widgets but if I copy-back these  into database (from
> entry widgets just loaded), these letters change to strange not-ascii
> char.
> 
> I would not be a database problem because if I print to video the sql
> insert strings, these contains the altready corrupted words.
> 
> How can I solve this problem?
> 
> Thanks,
> Filippo
> 
   Hi,

   maybe a

   $dh->do("SET client_encoding TO 'UTF8'");

   could help.

   Christoph

-- 
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop


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

Date: 17 May 2007 09:37:24 -0700
From: vikrant <vikrant.kansal@gmail.com>
Subject: Re: How to handling string contains single quote and double quote
Message-Id: <1179419844.917816.75440@q75g2000hsh.googlegroups.com>

On May 2, 11:23 am, Joe Smith <j...@inwap.com> wrote:
> vikrant wrote:
> > the code is a part of a
> > function,which called again and again.So,i thought  that opening and
> > closing a file on each call may effect the performance.That was the
> > only reason of using the system command.
> > Comments are most welcome.
>
> FYI: Invoking system() like that means 32 separate file operations each
> time it is called.
>
> linux% strace -f -e trace=file sh -c 'echo foo > temp.txt' |& cat -n
>       1  execve("/bin/sh", ["sh", "-c", "echo foo > temp.txt"], [/* 41 vars */]) = 0
>       2  access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
>       3  open("/etc/ld.so.cache", O_RDONLY)      = 3
>       4  fstat64(3, {st_mode=S_IFREG|0644, st_size=79328, ...}) = 0
>       5  open("/lib/libtermcap.so.2", O_RDONLY)  = 3
>       6  fstat64(3, {st_mode=S_IFREG|0755, st_size=12924, ...}) = 0
>       7  open("/lib/libdl.so.2", O_RDONLY)       = 3
>       8  fstat64(3, {st_mode=S_IFREG|0755, st_size=16244, ...}) = 0
>       9  open("/lib/libc.so.6", O_RDONLY)        = 3
>      10  fstat64(3, {st_mode=S_IFREG|0755, st_size=1485672, ...}) = 0
>      11  open("/dev/tty", O_RDWR|O_NONBLOCK|O_LARGEFILE) = 3
>      12  open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3
>      13  fstat64(3, {st_mode=S_IFREG|0644, st_size=49641600, ...}) = 0
>      14  open("/etc/mtab", O_RDONLY)             = 3
>      15  fstat64(3, {st_mode=S_IFREG|0644, st_size=414, ...}) = 0
>      16  open("/proc/meminfo", O_RDONLY)         = 3
>      17  fstat64(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
>      18  stat64("/home/jms", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0
>      19  stat64(".", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0
>      20  open("/usr/lib/gconv/gconv-modules.cache", O_RDONLY) = 3
>      21  fstat64(3, {st_mode=S_IFREG|0644, st_size=22294, ...}) = 0
>      22  open("/usr/lib/gconv/ISO8859-1.so", O_RDONLY) = 3
>      23  fstat64(3, {st_mode=S_IFREG|0755, st_size=5340, ...}) = 0
>      24  stat64(".", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0
>      25  stat64("/usr/bin/sh", 0xbff56eb4)       = -1 ENOENT (No such file or directory)
>      26  stat64("/usr/sbin/sh", 0xbff56eb4)      = -1 ENOENT (No such file or directory)
>      27  stat64("/bin/sh", {st_mode=S_IFREG|0755, st_size=686520, ...}) = 0
>      28  access("/bin/sh", X_OK)                 = 0
>      29  stat64("/bin/sh", {st_mode=S_IFREG|0755, st_size=686520, ...}) = 0
>      30  access("/bin/sh", X_OK)                 = 0
>      31  open("temp.txt", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666

Once again thanks for providing this valuable information.i shall try
to follow the above procedure to get the behavior of the code.

Regards,
vikrant



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

Date: 17 May 2007 00:40:11 -0700
From: Raymundo <gypark@gmail.com>
Subject: Modifying $_ in "map", with an array containing a gap...
Message-Id: <1179387611.712268.82960@o5g2000hsb.googlegroups.com>

Hello,

I'm sorry I'm not good at English. :-)


foreach and map functions show the same result when an array has no
gap.

@array = (1, 2, 3, 4);
foreach (@array) {
    $_ *= 10
}
# now, $array = (10, 20, 30, 40)

@array = (1, 2, 3, 4);
map { $_ *= 10 } @array;
# now, $array = (10, 20, 30, 40)


However, if an array contains a gap...

      1 $array1[0] = 0;
      2 $array1[9] = 9;          # now $array1 = (0, undef,
undef, ... , 9);
      3 print "@array1", "\n";   # 0 "" "" ... "" 9
      4 foreach (@array1) {
      5     $_ *= 10             # $array1 = (0, 0, 0, ... , 90)
      6 }
      7 print "@array1", "\n";   # 0 0 0 ... 0 90
      8
      9
     10 $array2[0] = 0;
     11 $array2[9] = 9;
     12 print "@array2", "\n";   # 0 "" "" ... "" 9
     13 map { $_ *= 10 } @array2; # ERROR!!!!!!
     14 print "@array2", "\n";

line 1-7 work well, but using map, line 13 reports an error:

Modification of a read-only value attempted at t2.pl line 13.


Before line 13, line 12 prints the intervening elements, treating
undef as null string. Then why does line 13 make such error? Is it a
bug? or...?



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

Date: Thu, 17 May 2007 10:22:39 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Modifying $_ in "map", with an array containing a gap...
Message-Id: <j54o435aripeacv01ekf9p5snhjipa7n9e@4ax.com>

On 16 May 2007 23:42:07 -0700, Raymundo <gypark@gmail.com> wrote:

>Subject: Modifying $_ in "map", with an array containing a gap...
          ^^^^^^^^^^^^^^^^^^^^^
          ^^^^^^^^^^^^^^^^^^^^^

DON'T! That's not what map() is for.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Thu, 17 May 2007 13:52:40 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Modifying $_ in "map", with an array containing a gap...
Message-Id: <f2hg1k$hvp$1@mlucom4.urz.uni-halle.de>

Raymundo wrote:
> foreach and map functions show the same result when 
> an array has no gap.

There are some misunderstanding  from your side ;)

>  1:  $array1[0] = 0;
>  2:  $array1[9] = 9;  # now $array1 = (0, undef, undef, ... , 9);
>  3:  print "@array1", "\n";   # 0 "" "" ... "" 9

Warning: "Use of uninitialized value in join or string at line 3."

>       4 foreach (@array1) {
>       5     $_ *= 10             # $array1 = (0, 0, 0, ... , 90)
>       6 }

Warning: "Use of uninitialized value in multiplication (*) at line 5."

>       7 print "@array1", "\n";   # 0 0 0 ... 0 90
>       8

No more warnings on #7, because the for *did* convert undef to numeric 0

>      10 $array2[0] = 0;
>      11 $array2[9] = 9;
>      12 print "@array2", "\n";   # 0 "" "" ... "" 9

Warning: Use of uninitialized value in join or string at line 12.

>      13 map { $_ *= 10 } @array2; # ERROR!!!!!!

Error: "Modification of a read-only value attempted at line 13."

Do you understand, what this error means? $_ can't be written
to ($_ = $_ * 10) in a map.

> Before line 13, line 12 prints the intervening elements, treating
> undef as null string. Then why does line 13 make such error? Is it a
> bug? or...?

No. The map operator is intended to convert one list, element by element,
into a new list, leaving the old list as it is. The 'correct' usage of
map would be, in your case:

       13:  my @array3 = map { $_ * 10 } @array2;
       14:  print "@array3", "\n";


Regards

Mirco


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

Date: Thu, 17 May 2007 14:20:01 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Modifying $_ in "map", with an array containing a gap...
Message-Id: <pan.2007.05.17.12.20.14@rtij.nl.invlalid>

On Thu, 17 May 2007 10:22:39 +0200, Michele Dondi wrote:

> On 16 May 2007 23:42:07 -0700, Raymundo <gypark@gmail.com> wrote:
> 
>>Subject: Modifying $_ in "map", with an array containing a gap...
>           ^^^^^^^^^^^^^^^^^^^^^
>           ^^^^^^^^^^^^^^^^^^^^^
> 
> DON'T! That's not what map() is for.
> 

From perldoc -f map:

           Note that $_ is an alias to the list value, so it can be used
           to modify the elements of the LIST.  While this is useful and
           supported, it can cause bizarre results if the elements of LIST
           are not variables.  Using a regular "foreach" loop for this
           purpose would be clearer in most cases. 

So modifying $_ is supported, but as undef is not a variable we get 
bizarre results.

This is clearly one of those cases where it isn't a bug, it's a 
feature. :-)



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

Date: Thu, 17 May 2007 16:02:58 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Modifying $_ in "map", with an array containing a gap...
Message-Id: <c0oo4316ba6m7u12tffj8f59ig4urca88l@4ax.com>

On Thu, 17 May 2007 14:20:01 +0200, Martijn Lievaart
<m@rtij.nl.invlalid> wrote:

>This is clearly one of those cases where it isn't a bug, it's a 
>feature. :-)

I didn't want to imply it were a bug, in fact I didn't write so.
Indeed I know it is supported and in very rare situations may also be
useful. But generally you use map() to *map* a list to another list,
which its main use.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 17 May 2007 08:02:40 -0700
From: "ron.hartikka@gmail.com" <ron.hartikka@gmail.com>
Subject: Re: Modifying $_ in "map", with an array containing a gap...
Message-Id: <1179414160.443787.312350@h2g2000hsg.googlegroups.com>


$array2[0] = 0;
$array2[9] = 9;
print "@array2", "\n";   # 0 "" "" ... "" 9
map { defined $_ ? $_ *= 10 : 0 } @array2;
print "@array2", "\n";   # 0 "" "" ... "" 90



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

Date: 17 May 2007 15:14:12 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Modifying $_ in "map", with an array containing a gap...
Message-Id: <slrnf4osa5.gfv.glennj@smeagol.ncf.ca>

At 2007-05-17 11:02AM, "ron.hartikka@gmail.com" wrote:
>  
>  $array2[0] = 0;
>  $array2[9] = 9;
>  print "@array2", "\n";   # 0 "" "" ... "" 9
>  map { defined $_ ? $_ *= 10 : 0 } @array2;
>  print "@array2", "\n";   # 0 "" "" ... "" 90

Of course, @array2 no longer contains undefined values at this point:
it contains zeroes instead.


-- 
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry


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

Date: Thu, 17 May 2007 17:13:08 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Modifying $_ in "map", with an array containing a gap...
Message-Id: <f2hrpf$l4k$2@mlucom4.urz.uni-halle.de>

ron.hartikka@gmail.com wrote:
> $array2[0] = 0;
> $array2[9] = 9;
> print "@array2", "\n";   # 0 "" "" ... "" 9
> map { defined $_ ? $_ *= 10 : 0 } @array2;

    map { $_ *= 10 if defined } @array2;

will do in the context.

> print "@array2", "\n";   # 0 "" "" ... "" 90

I think it's generally a bad practice to
emphasize such solutions which are clearly
of bad style and will lead to dozens of
warnings under 'use warnings'.

Regards

Mirco


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

Date: Thu, 17 May 2007 17:16:29 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Modifying $_ in "map", with an array containing a gap...
Message-Id: <f2hrvo$l4k$3@mlucom4.urz.uni-halle.de>

Glenn Jackman wrote:
> At 2007-05-17 11:02AM, "ron.hartikka@gmail.com" wrote:
>>  
>>  $array2[0] = 0;
>>  $array2[9] = 9;
>>  print "@array2", "\n";   # 0 "" "" ... "" 9
>>  map { defined $_ ? $_ *= 10 : 0 } @array2;
>>  print "@array2", "\n";   # 0 "" "" ... "" 90
> 
> Of course, @array2 no longer contains undefined values at this point:
> it contains zeroes instead.

Wrong guess ;)

Of course will @array2 keep the undefs.

Regards

Mirco


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

Date: 17 May 2007 15:36:20 GMT
From: xhoster@gmail.com
Subject: Re: Modifying $_ in "map", with an array containing a gap...
Message-Id: <20070517113621.448$tX@newsreader.com>

Raymundo <gypark@gmail.com> wrote:
> Hello,
>
> I'm sorry I'm not good at English. :-)
>
> foreach and map functions show the same result when an array has no
> gap.
>
> @array = (1, 2, 3, 4);
> foreach (@array) {
>     $_ *= 10
> }
> # now, $array = (10, 20, 30, 40)
>
> @array = (1, 2, 3, 4);
> map { $_ *= 10 } @array;
> # now, $array = (10, 20, 30, 40)
>
> However, if an array contains a gap...
>
>       1 $array1[0] = 0;
>       2 $array1[9] = 9;          # now $array1 = (0, undef,
> undef, ... , 9);
>       3 print "@array1", "\n";   # 0 "" "" ... "" 9
>       4 foreach (@array1) {
>       5     $_ *= 10             # $array1 = (0, 0, 0, ... , 90)
>       6 }
>       7 print "@array1", "\n";   # 0 0 0 ... 0 90
>       8
>       9
>      10 $array2[0] = 0;
>      11 $array2[9] = 9;
>      12 print "@array2", "\n";   # 0 "" "" ... "" 9
>      13 map { $_ *= 10 } @array2; # ERROR!!!!!!
>      14 print "@array2", "\n";
>
> line 1-7 work well, but using map, line 13 reports an error:
>
> Modification of a read-only value attempted at t2.pl line 13.
>
> Before line 13, line 12 prints the intervening elements, treating
> undef as null string. Then why does line 13 make such error? Is it a
> bug? or...?

I don't know about a bug, but at least a mal-feature, I would say.
There is a special kind of fly-weight undef used in sparse arrays.
It should get promoted to the other kind of undef automatically when
needed.  Apparently being aliased through map or grep inhibits this
automatic promotion, while being aliased through foreach doesn't inhibit
it.


This also gives the error:

perl -le 'my @x; $x[5]=5; $_*=10 foreach grep 1, @x; print "@x"'


removing the "grep 1," also removes the error.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 17 May 2007 12:09:09 -0500
From: Lawrence Statton <yankeeinexile@gmail.com>
Subject: Re: Modifying $_ in "map", with an array containing a gap...
Message-Id: <874pmbml6y.fsf@gmail.com>

Glenn Jackman <glennj@ncf.ca> writes:
> At 2007-05-17 11:02AM, "ron.hartikka@gmail.com" wrote:
> >  
> >  $array2[0] = 0;
> >  $array2[9] = 9;
> >  print "@array2", "\n";   # 0 "" "" ... "" 9
> >  map { defined $_ ? $_ *= 10 : 0 } @array2;
> >  print "@array2", "\n";   # 0 "" "" ... "" 90
> 
> Of course, @array2 no longer contains undefined values at this point:
> it contains zeroes instead.
> 

You've been told you're wrong, but not why ... 

map is being evaluated in a void context, so the list that is being
thrown into the bit bucket contains zeros where @array2 was undefined.
$_ is only being altered in those cases where it was defined.

-- 
	Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
place them into the correct order.


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

Date: 17 May 2007 10:28:14 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: Modifying $_ in "map", with an array containing a gap...
Message-Id: <1179422894.769731.305650@y80g2000hsf.googlegroups.com>

On May 17, 8:40 am, Raymundo <gyp...@gmail.com> wrote:

> I'm sorry I'm not good at English. :-)

Good enough.

> foreach and map functions show the same result when an array has no
> gap.
>
> @array = (1, 2, 3, 4);
> foreach (@array) {
>     $_ *= 10}
>
> # now, $array = (10, 20, 30, 40)
>
> @array = (1, 2, 3, 4);
> map { $_ *= 10 } @array;
> # now, $array = (10, 20, 30, 40)
>
> However, if an array contains a gap...
>
>       1 $array1[0] = 0;
>       2 $array1[9] = 9;          # now $array1 = (0, undef,
> undef, ... , 9);
>       3 print "@array1", "\n";   # 0 "" "" ... "" 9
>       4 foreach (@array1) {
>       5     $_ *= 10             # $array1 = (0, 0, 0, ... , 90)
>       6 }
>       7 print "@array1", "\n";   # 0 0 0 ... 0 90
>       8
>       9
>      10 $array2[0] = 0;
>      11 $array2[9] = 9;
>      12 print "@array2", "\n";   # 0 "" "" ... "" 9
>      13 map { $_ *= 10 } @array2; # ERROR!!!!!!
>      14 print "@array2", "\n";
>
> line 1-7 work well, but using map, line 13 reports an error:
>
> Modification of a read-only value attempted at t2.pl line 13.
>
> Before line 13, line 12 prints the intervening elements, treating
> undef as null string. Then why does line 13 make such error? Is it a
> bug? or...?

Yes it's a bug.

The subtly is the difference between elements of an array that are
undef and ones that are non-existent.

See "perldoc -f exsts".

If I say..

my @array2;
$array2[0] = 0;
$array2[9] = 9;

 ..then elements 1..8 of @array are not just undef but non-existent.

In for() there is special magic to allow you to have a reference to a
non-existent element of an array without it becoming autovivified.

In map() there's evidently no such magic. In the LIST argument in
map() any non-existent elements are replaced by the "one true undef"
aka PL_sv_undef. (The one you get a reference to by saying \undef).

IMNSHO this needs to be explained in "perldoc -f map" or changed.

Note: if you think what map() does is odd then consider what happens
if you pass a gappy array to a subroutine! Here gap in the argument
leave gaps in @_ but modifying the missing element in @_ gives no
error but does not modify the missing element in the original array.

sub inc {
    for my $i ( 0.. $#_ ) {
	$_[$i]++;
    }
}

my @array;
$array[1]=666;

inc @array;

print join ',' => @array; # ,667



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

Date: Thu, 17 May 2007 19:34:30 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Modifying $_ in "map", with an array containing a gap...
Message-Id: <lf4p435ukb6oohtck1oq2hh2otiobflp04@4ax.com>

On 17 May 2007 15:36:20 GMT, xhoster@gmail.com wrote:

>needed.  Apparently being aliased through map or grep inhibits this
>automatic promotion, while being aliased through foreach doesn't inhibit
>it.

Thank you. While I still repeat my initial reply to the OP, the issue
was subtler than I had understood.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 17 May 2007 06:21:57 -0700
From: Googy <cooldudevamsee@gmail.com>
Subject: Problem with perl group capture.
Message-Id: <1179408117.490749.38460@e65g2000hsc.googlegroups.com>

Hi,

I am executing two regex one after one. each one contains one group
capture.

The problem I am facing is after executing first regex I am getting a
string into $1.  After execting second regular expression $1 contains
result from first regex execution.

Kindly provide a solution if you have faced this kind of problem.

Thanks.



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

Date: Thu, 17 May 2007 09:25:53 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Problem with perl group capture.
Message-Id: <m2wsz7eg4e.fsf@local.wv-www.com>

Googy <cooldudevamsee@gmail.com> writes:

> The problem I am facing is after executing first regex I am getting a
> string into $1.  After execting second regular expression $1 contains
> result from first regex execution.

The second regex didn't match. Always check for a successful match before
trying to use $1 and friends.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Thu, 17 May 2007 16:06:12 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Problem with perl group capture.
Message-Id: <f7oo43l08gmmk48t8po3erlgh7lbvogmq1@4ax.com>

On 17 May 2007 06:21:57 -0700, Googy <cooldudevamsee@gmail.com> wrote:

>The problem I am facing is after executing first regex I am getting a
>string into $1.  After execting second regular expression $1 contains
>result from first regex execution.

Does the second regex also contain grouping. If not, then what you're
seeing is expected. Otherwise, it's still expected, if the second
regex did not match.

>Kindly provide a solution if you have faced this kind of problem.

*Which* problem? Are you perhaps forgetting to check whether the
matches succeeded at all?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Thu, 17 May 2007 14:29:49 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: regular expressions?
Message-Id: <pan.2007.05.17.12.30.02@rtij.nl.invlalid>

On Wed, 16 May 2007 18:53:45 -0700, Ivan wrote:

> Hi all..
> 
> I'm in need of some help..
> 
> I'm looking after a subversion machine with many repositories and many
> users in the passwd files for each..
> 
> Currently when I want to get rid of one of the users, I normally have to
> go through each repository, look in the passwd file and delete the user
> manually..
> 
> I'm assuming with perl I might be able to make up a quick script that
> will look inside each repo, find the line with the user, delete it and
> save the file.. It will save a lot of my time..
> 
> Either a perl script or a shell script might be suitable for this.. All
> I got at the moment is the command line: grep -l "troppd" */conf/ passwd
> So instead of going through hundreds of repositories, I only have to go
> into the ones where "troppd" appears and I can delete it..

Here's how I would do this. I assume these passwd files are regular 
passwd files, so I can assume the username starts at the beginning of the 
line followed by a colon. If this is assumption is not correct, slight 
modifications will be needed to the regexps.

$TODELETE="troppd"
perl -n -i.bak -e "/^$TODELETE:/ or print" \
      $(grep -l "^$TODELETE:" */conf/ passwd)

This can also be solved easily with sed or awk, but perl has a convenient 
in-place edit with the -i switch. See perldoc perlrun for a description 
of these switches.

Also note that this only modifies the files that do contain the user, 
which you most probably will want. Otherwise leave out the grep part and 
operate on */conf/passwd directly.

As the above is untested code, I would test thoroughly before running 
this in production!

HTH,
M4


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

Date: 17 May 2007 10:32:55 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: regular expressions?
Message-Id: <1179423175.871040.133580@p77g2000hsh.googlegroups.com>

On May 17, 2:53 am, Ivan <find.i...@gmail.com> wrote:

> Subject:  regular expressions?

Please put the subject of your post in the Subject of your post.



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

Date: Wed, 16 May 2007 16:38:13 -0500
From: "Mario D'Alessio" <dalessio@motorola.NOSPAM.com>
Subject: Re: Simple Regular Expression Help
Message-Id: <f2ftvl$bli$1@newshost.mot.com>


<vunet.us@gmail.com> wrote in message 
news:1179337861.793364.184800@e65g2000hsc.googlegroups.com...
> How can I strip this line with regular expession to get 12345 number
> within brackets:
>
> $line = "some text is here (12345 ms)";
>
> This did not work:
>
> $text = $line;
> $text =~ m/\((\d+)\)/;

You didn't account for the "ms" in the text string:

$text =~ m/\((\d+) ms\)/;

or if there can be other strings other than "ms":

$text =~ m/\((\d+).*\)/;

Mario 




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

Date: 17 May 2007 06:57:20 -0700
From: vunet.us@gmail.com
Subject: Sorting Hash by Value and Key
Message-Id: <1179410240.423940.57010@q23g2000hsg.googlegroups.com>

Could someone show how to sort my hash by values (primary sorting) and
then by key for the same values:

%grades = (
	0 => 70,
	1 => 50,
	6 => 90,
	5 => 90,
	4 => 90,
);

I want to see:
	1 => 50
	0 => 70
	4 => 90
	5 => 90
	6 => 90

Thank you



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

Date: Thu, 17 May 2007 16:11:07 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Sorting Hash by Value and Key
Message-Id: <fboo43pc943ntuh9780iuf7fcb8ud1lrgc@4ax.com>

On 17 May 2007 06:57:20 -0700, vunet.us@gmail.com wrote:

>Could someone show how to sort my hash by values (primary sorting) and
>then by key for the same values:

You can't sort a *hash*. I suppose you want to sort its keys(). Don't
you?

>%grades = (
>	0 => 70,
>	1 => 50,
>	6 => 90,
>	5 => 90,
>	4 => 90,
>);
>
>I want to see:
>	1 => 50

A hash is intrinsically unsorted. Get a list of arrayrefs instead.

>	0 => 70

Are you sure you want a hash, anyway? Those keys seem to better suited
for a regular array.

>	4 => 90
>	5 => 90
>	6 => 90

What have you tried thus far? Well, let's spoon-feed you anyway:

  my @sorted=sort {$a->[1] <=> $b->[1] or $a->[0] <=> $b->[0]}
    map [$_ => $grades{$_}], keys %grades;


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 17 May 2007 10:12:51 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Sorting Hash by Value and Key
Message-Id: <87fy5vh730.fsf@mithril.chromatico.net>

>>>>> "v" == vunet us <vunet.us@gmail.com> writes:

    v> Could someone show how to sort my hash by values (primary
    v> sorting) and then by key for the same values:

Because of the way hashes are represented internally, it is
inefficient to maintain them in a sorted order.  In other words, you
can't sort a hash.  (You can in other languages, yes.  If you want
them, you know where to find them.)

What you *can* do is sort a list of hash keys based on the values they
have in a particular hash.  See perldoc perlfaq4 under "How do I sort
a hash (optionally by value instead of key)?"

Charlton


-- 
Charlton Wilbur
cwilbur@chromatico.net


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

Date: Thu, 17 May 2007 17:05:17 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Sorting Hash by Value and Key
Message-Id: <f2hrao$l4k$1@mlucom4.urz.uni-halle.de>

vunet.us@gmail.com wrote:
> Could someone show how to sort my hash by values (primary sorting) and
> then by key for the same values:
> 
> %grades = (
> 	0 => 70,
> 	1 => 50,
> 	6 => 90,
> 	5 => 90,
> 	4 => 90,
> );
> 
> I want to see:
> 	1 => 50
> 	0 => 70
> 	4 => 90
> 	5 => 90
> 	6 => 90

In addition to the solutions and hints given
already by Michele and Charlton, you could
simply construct another hash which holds
your sort criteria as the 'key', like


    my %grades = (
       0 => 70, 	1 => 50,
       6 => 90,	5 => 90,
       4 => 90     );

    my %hsort= map +($grades{$_}.$_,$_), keys %grades;

    print "$hsort{$_} $grades{ $hsort{$_} }\n" for sort keys %hsort;



more another solutions of course possible.

Regards

M.


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

Date: Thu, 17 May 2007 20:37:59 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Test harness for scripts?
Message-Id: <464c3071$0$2869$afc38c87@news.optusnet.com.au>


<bwooster47@gmail.com> wrote in message 
news:1179344869.181841.195250@o5g2000hsb.googlegroups.com...
> When creating Perl modules, there is Test::More and similar tools
> available to automate the testing.
>
> Are there general guidelines for writing test scripts that work with
> the Test::Harness framework?

Any file with a '.t' extension that's placed in the './t' folder will be 
automatically run by 'make test'.
There are other options, too, but that's how most people create their test 
scripts.

 .
 .
> But how to run the command - "make test"
> puts the script in blib/script, the script itself is in bin/, and
> there may be a system installed old script version, so need to make
> sure that the test is running the script from the development folder.
>

I don't think this is a consideration at all.
The test scripts themselves (ie the '.t' scripts in the './t' folder) don't 
get put into blib - they stay where they are.
Also, 'make test' will find (and use) the files in blib *before* it goes 
looking for files (in @INC) that have been installed into perl as a result 
of an earlier build. (That is, if the file exists in blib, then that's the 
one that 'make test' is going to use.)

Cheers,
Rob 



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

Date: 17 May 2007 01:13:16 -0700
From: shane.buggins41@ntlworld.com
Subject: Watch Television online for free.
Message-Id: <1179389596.900972.230690@y80g2000hsf.googlegroups.com>

Watch television online now for free.

Includes television channels from all over the world and sport events
from all over the world including, NBA, Soccer, Motor Racing and much
more.

http://homepage.ntlworld.com/louise.randall41



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

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


Administrivia:

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

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

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

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

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


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


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