[23682] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5889 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 3 18:10:42 2003

Date: Wed, 3 Dec 2003 15:10:14 -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           Wed, 3 Dec 2003     Volume: 10 Number: 5889

Today's topics:
        regexp subpatterns backreference <chatasos@yahoo.com>
    Re: regexp subpatterns backreference <nobull@mail.com>
    Re: regexp subpatterns backreference <noreply@gunnar.cc>
    Re: regexp subpatterns backreference <chatasos@yahoo.com>
    Re: regexp subpatterns backreference <noreply@gunnar.cc>
    Re: regexp subpatterns backreference <chatasos@yahoo.com>
    Re: regexp subpatterns backreference <noreply@gunnar.cc>
        return the array index for a given value <eddGallary2@hotmail.com>
    Re: return the array index for a given value <eddGallary2@hotmail.com>
    Re: return the array index for a given value <nospam@bigpond.com>
    Re: return the array index for a given value <bmb@ginger.libs.uga.edu>
    Re: return the array index for a given value (Malcolm Dew-Jones)
    Re: return the array index for a given value <tore@aursand.no>
    Re: return the array index for a given value (Anno Siegel)
    Re: return the array index for a given value (Tad McClellan)
    Re: return the array index for a given value <usenet@morrow.me.uk>
        string matching question. (Mohammed Ishaq)
    Re: string matching question. <noreply@gunnar.cc>
        Useless use of private variable in void context at pars <jon.rogers@tv.tu>
    Re: Useless use of private variable in void context at  (Anno Siegel)
    Re: Useless use of private variable in void context at  (Tad McClellan)
    Re: using GD module <syscjm@gwu.edu>
        using xs -- trouble dereferencing (Jim)
        Win32::OLE and creation of pivot table in Excel <joeminga@yahoo.com>
    Re: Win32::OLE and creation of pivot table in Excel <ben.liddicott@comodogroup.com>
    Re: Win32::OLE and creation of pivot table in Excel <joeminga@yahoo.com>
    Re: Win32::OLE and creation of pivot table in Excel <karlheinz.weindl@oooonlinehome.de>
    Re: Your code doesn't work <dover@nortelnetworks.com>
    Re: Your code doesn't work <bik.mido@tiscalinet.it>
    Re: Your code doesn't work (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 03 Dec 2003 18:49:46 +0200
From: Tassos <chatasos@yahoo.com>
Subject: regexp subpatterns backreference
Message-Id: <1070470288.429005@athprx02>


I'm using the following file as a reference:

#------------------------file 1---------------------
%LINK-3-UPDOWN : Interface [chars1], changed state to [chars2]
%FR-5-DLCICHANGE : Interface [chars1] - DLCI [dec1] state changed to [chars2]
#------------------------------------------------

which gets converted (after a substitution of [xxx] with the appropriate regexp) to the 
following file:

#-----------------------file 2----------------------
%LINK-3-UPDOWN : Interface ([\w\-\./]+), changed state to (\w+)
%FR-5-DLCICHANGE : Interface ([\w\-\./]+) - DLCI (\d+) state changed to (\w+)
#------------------------------------------------

which will try to match the following file (so i can get some variables):

#----------------------file 3--------------------------
%LINK-3-UPDOWN: Interface Ethernet0, changed state to up
%FR-5-DLCICHANGE: Interface Serial3/0 - DLCI 169 state changed to INACTIVE
#------------------------------------------------

The problem is that if i try to match file 3 to file 2, i get the following variables:

$1 = Ethernet0	([chars1] in file1)
$2 = up		([chars1] in file1)

for the 1st line (%LINK-3-UPDOWN) and

$1 = Serial3/0	([chars1] in file1)
$2 = 169	([dec1] in file1)
$3 = INACTIVE	([chars2] in file1)

for the 2nd line (%FR-5-DLCICHANGE), but i need

$1 = Serial3/0	([chars1] in file1)
$2 = INACTIVE	([chars2] in file1)
$3 = 169	([dec1] in file1)

for the 2nd line (%FR-5-DLCICHANGE).

Is there a way i can have $1, $2, $x mapped to the same [xxxx] every time?




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

Date: 03 Dec 2003 18:10:53 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: regexp subpatterns backreference
Message-Id: <u9n0a9vkk2.fsf@wcl-l.bham.ac.uk>

Tassos <chatasos@yahoo.com> writes:


> #------------------------file 1---------------------
> %LINK-3-UPDOWN : Interface [chars1], changed state to [chars2]
> %FR-5-DLCICHANGE : Interface [chars1] - DLCI [dec1] state changed to [chars2]
> #------------------------------------------------
> 
> which gets converted (after a substitution of [xxx] with the
> appropriate regexp) to the following file:
> 
> #-----------------------file 2----------------------
> %LINK-3-UPDOWN : Interface ([\w\-\./]+), changed state to (\w+)
> %FR-5-DLCICHANGE : Interface ([\w\-\./]+) - DLCI (\d+) state changed to (\w+)
> #------------------------------------------------
> 
> which will try to match the following file (so i can get some
> variables):
> 
> #----------------------file 3--------------------------
> %LINK-3-UPDOWN: Interface Ethernet0, changed state to up
> %FR-5-DLCICHANGE: Interface Serial3/0 - DLCI 169 state changed to INACTIVE
> #------------------------------------------------
> 
> The problem is that if i try to match file 3 to file 2, i get the following variables:
> 
> $1 = Ethernet0	([chars1] in file1)
> $2 = up		([chars1] in file1)
> 
> for the 1st line (%LINK-3-UPDOWN) and
> 
> $1 = Serial3/0	([chars1] in file1)
> $2 = 169	([dec1] in file1)
> $3 = INACTIVE	([chars2] in file1)
> 
> for the 2nd line (%FR-5-DLCICHANGE), but i need
> 
> $1 = Serial3/0	([chars1] in file1)
> $2 = INACTIVE	([chars2] in file1)
> $3 = 169	([dec1] in file1)
> 
> for the 2nd line (%FR-5-DLCICHANGE).
> 
> Is there a way i can have $1, $2, $x mapped to the same [xxxx] every time?

No, there's no way of naming captures in Perl.

Rather than having file2 contain just plain Perl regex it will need to
contain a list of names for the captures and then a regex:

#-----------------------file 2----------------------
chars1,chars2 %LINK-3-UPDOWN : Interface ([\w\-\./]+), changed state to (\w+)
chars1,dec1,chars2 %FR-5-DLCICHANGE : Interface ([\w\-\./]+) - DLCI (\d+) state changed to (\w+)
#------------------------------------------------

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


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

Date: Wed, 03 Dec 2003 19:41:16 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regexp subpatterns backreference
Message-Id: <bqlark$22lsl9$1@ID-184292.news.uni-berlin.de>

Tassos wrote:
> ... i get the following variables:
> 
> $1 = Ethernet0    ([chars1] in file1)
> $2 = up        ([chars1] in file1)
> 
> for the 1st line (%LINK-3-UPDOWN) and
> 
> $1 = Serial3/0    ([chars1] in file1)
> $2 = 169    ([dec1] in file1)
> $3 = INACTIVE    ([chars2] in file1)
> 
> for the 2nd line (%FR-5-DLCICHANGE)

<snip>

> Is there a way i can have $1, $2, $x mapped to the same [xxxx]
> every time?

One way is to use the same regex for both lines.

     my $regex = qr/Interface\s+([\w\-\.\/]+)            # $1
                    (?:.+DLCI\s+(\d+))?                  # $2
                    .+changed(?:\s+state)?\s+to\s+(\w+)  # $3
                   /x;

     while (<DATA>) {
         if (/$regex/) {
             print "Line $.:\n";
             print "\$1 = $1\n\$2 = $2\n\$3 = $3\n\n";
         }
     }

Printed output:
     Line 1:
     $1 = Ethernet0
     $2 =
     $3 = up

     Line 2:
     $1 = Serial3/0
     $2 = 169
     $3 = INACTIVE

__DATA__
%LINK-3-UPDOWN: Interface Ethernet0, changed state to up
%FR-5-DLCICHANGE: Interface Serial3/0 - DLCI 169 state changed to INACTIVE

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



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

Date: Wed, 03 Dec 2003 20:52:05 +0200
From: Tassos <chatasos@yahoo.com>
Subject: Re: regexp subpatterns backreference
Message-Id: <1070477628.381288@athprx02>



Gunnar Hjalmarsson wrote:

> 
> Tassos wrote:
> 
>> ... i get the following variables:
>>
>> $1 = Ethernet0    ([chars1] in file1)
>> $2 = up        ([chars1] in file1)
>>
>> for the 1st line (%LINK-3-UPDOWN) and
>>
>> $1 = Serial3/0    ([chars1] in file1)
>> $2 = 169    ([dec1] in file1)
>> $3 = INACTIVE    ([chars2] in file1)
>>
>> for the 2nd line (%FR-5-DLCICHANGE)
> 
> 
> <snip>
> 
>> Is there a way i can have $1, $2, $x mapped to the same [xxxx]
>> every time?
> 
> 
> One way is to use the same regex for both lines.
> 
>     my $regex = qr/Interface\s+([\w\-\.\/]+)            # $1
>                    (?:.+DLCI\s+(\d+))?                  # $2
>                    .+changed(?:\s+state)?\s+to\s+(\w+)  # $3
>                   /x;
> 

Is i only had those 2 lines, then that would be a good solution.
But file3 (DATA) contains 50+ quite DIFFERENT lines and i suppose a regex for all of them 
would be a big problem...

>     while (<DATA>) {
>         if (/$regex/) {
>             print "Line $.:\n";
>             print "\$1 = $1\n\$2 = $2\n\$3 = $3\n\n";
>         }
>     }
> 
> Printed output:
>     Line 1:
>     $1 = Ethernet0
>     $2 =
>     $3 = up
> 
>     Line 2:
>     $1 = Serial3/0
>     $2 = 169
>     $3 = INACTIVE
> 
> __DATA__
> %LINK-3-UPDOWN: Interface Ethernet0, changed state to up
> %FR-5-DLCICHANGE: Interface Serial3/0 - DLCI 169 state changed to INACTIVE
> 



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

Date: Wed, 03 Dec 2003 19:59:30 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regexp subpatterns backreference
Message-Id: <bqlbu3$2496g5$1@ID-184292.news.uni-berlin.de>

Tassos wrote:
> Gunnar Hjalmarsson wrote:
>> One way is to use the same regex for both lines.
>> 
>>     my $regex = qr/Interface\s+([\w\-\.\/]+)            # $1
>>                    (?:.+DLCI\s+(\d+))?                  # $2
>>                    .+changed(?:\s+state)?\s+to\s+(\w+)  # $3
>>                   /x;
> 
> Is i only had those 2 lines, then that would be a good solution. 
> But file3 (DATA) contains 50+ quite DIFFERENT lines and i suppose a
> regex for all of them would be a big problem...

I see. Brian's suggestion should work, I suppose.

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



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

Date: Wed, 03 Dec 2003 21:12:33 +0200
From: Tassos <chatasos@yahoo.com>
Subject: Re: regexp subpatterns backreference
Message-Id: <1070478855.789378@athprx02>



Brian McCauley wrote:

> Tassos <chatasos@yahoo.com> writes:
> 
> 
> 
>>#------------------------file 1---------------------
>>%LINK-3-UPDOWN : Interface [chars1], changed state to [chars2]
>>%FR-5-DLCICHANGE : Interface [chars1] - DLCI [dec1] state changed to [chars2]
>>#------------------------------------------------
>>
>>which gets converted (after a substitution of [xxx] with the
>>appropriate regexp) to the following file:
>>
>>#-----------------------file 2----------------------
>>%LINK-3-UPDOWN : Interface ([\w\-\./]+), changed state to (\w+)
>>%FR-5-DLCICHANGE : Interface ([\w\-\./]+) - DLCI (\d+) state changed to (\w+)
>>#------------------------------------------------
>>
>>which will try to match the following file (so i can get some
>>variables):
>>
>>#----------------------file 3--------------------------
>>%LINK-3-UPDOWN: Interface Ethernet0, changed state to up
>>%FR-5-DLCICHANGE: Interface Serial3/0 - DLCI 169 state changed to INACTIVE
>>#------------------------------------------------
>>
>>The problem is that if i try to match file 3 to file 2, i get the following variables:
>>
>>$1 = Ethernet0	([chars1] in file1)
>>$2 = up		([chars1] in file1)
>>
>>for the 1st line (%LINK-3-UPDOWN) and
>>
>>$1 = Serial3/0	([chars1] in file1)
>>$2 = 169	([dec1] in file1)
>>$3 = INACTIVE	([chars2] in file1)
>>
>>for the 2nd line (%FR-5-DLCICHANGE), but i need
>>
>>$1 = Serial3/0	([chars1] in file1)
>>$2 = INACTIVE	([chars2] in file1)
>>$3 = 169	([dec1] in file1)
>>
>>for the 2nd line (%FR-5-DLCICHANGE).
>>
>>Is there a way i can have $1, $2, $x mapped to the same [xxxx] every time?
> 
> 
> No, there's no way of naming captures in Perl.
> 
> Rather than having file2 contain just plain Perl regex it will need to
> contain a list of names for the captures and then a regex:
> 
> #-----------------------file 2----------------------
> chars1,chars2 %LINK-3-UPDOWN : Interface ([\w\-\./]+), changed state to (\w+)
> chars1,dec1,chars2 %FR-5-DLCICHANGE : Interface ([\w\-\./]+) - DLCI (\d+) state changed to (\w+)
> #------------------------------------------------
> 

Ok, let's suppose i do that (file2 is actually an array, so it wouldn't be a problem).

Then, how do i make the new mapping between the captures and the regex?



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

Date: Wed, 03 Dec 2003 21:59:17 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regexp subpatterns backreference
Message-Id: <bqlivo$24lad5$1@ID-184292.news.uni-berlin.de>

Tassos wrote:
> Brian McCauley wrote:
>> Rather than having file2 contain just plain Perl regex it will
>> need to contain a list of names for the captures and then a
>> regex:
>> 
>> #-----------------------file 2----------------------
>> chars1,chars2 %LINK-3-UPDOWN : Interface ([\w\-\./]+), changed state to (\w+)
>> chars1,dec1,chars2 %FR-5-DLCICHANGE : Interface ([\w\-\./]+) - DLCI (\d+) state changed to (\w+)
>> #------------------------------------------------
> 
> Ok, let's suppose i do that (file2 is actually an array, so it
> wouldn't be a problem).
> 
> Then, how do i make the new mapping between the captures and the
> regex?

Maybe something like this:

     while (<DATA>) {
         my ($keys, $regex) = split /\s+/, shift @file2, 2;
         my %vars = ();
         if ( ( @vars{ split /,/, $keys } = /$regex/ ) > 0 ) {
             print "Line $.:\n";
             for (keys %vars) {
                 print "\$vars{$_} = $vars{$_}\n";
             }
             print "\n";
         }
     }

Printed output:
     Line 1:
     $vars{chars1} = Ethernet0
     $vars{chars2} = up

     Line 2:
     $vars{dec1} = 169
     $vars{chars1} = Serial3/0
     $vars{chars2} = INACTIVE

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



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

Date: Thu, 04 Dec 2003 07:28:37 +1100
From: Edo <eddGallary2@hotmail.com>
Subject: return the array index for a given value
Message-Id: <3FCE4775.1090301@hotmail.com>

Hello
is there a ready perl function to return the index of a given value in 
an array?

thanks



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

Date: Thu, 04 Dec 2003 07:58:18 +1100
From: Edo <eddGallary2@hotmail.com>
Subject: Re: return the array index for a given value
Message-Id: <3FCE4E6A.1010706@hotmail.com>

Edo wrote:
> Hello
> is there a ready perl function to return the index of a given value in 
> an array?
> 
> thanks
> 


by the same way of thinking,

is there a ready perl function to return a hash slice from a grand hash 
starting at a given key and covers n numbers of the following sorted keys?



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

Date: Thu, 04 Dec 2003 07:17:12 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: return the array index for a given value
Message-Id: <16247563.J6JpO2EZd3@gregs-web-hosting-and-pickle-farming>

It was a dark and stormy night, and Edo managed to scribble:

> Hello
> is there a ready perl function to return the index of a given value in
> an array?
> 
> thanks

Use a hash instead.

gtoomey


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

Date: Wed, 3 Dec 2003 16:27:48 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: return the array index for a given value
Message-Id: <Pine.A41.4.58.0312031626500.20218@ginger.libs.uga.edu>

On Thu, 4 Dec 2003, Edo wrote:

> Hello
> is there a ready perl function to return the index of a given value in
> an array?
>
> thanks
>
>

Try this FAQ: How do I find the first array element for which a condition
              is true?

Regards,

Brad


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

Date: 3 Dec 2003 13:36:22 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: return the array index for a given value
Message-Id: <3fce5756@news.victoria.tc.ca>

Edo (eddGallary2@hotmail.com) wrote:
: Hello
: is there a ready perl function to return the index of a given value in 
: an array?

Let me guess

my $i=-1;
foreach my $element (@array)
{	$i++;
	print "Array element $i matched\n"
		if ( $element =~ m/$wanted/) ;
}




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

Date: Wed, 03 Dec 2003 22:36:56 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: return the array index for a given value
Message-Id: <pan.2003.12.03.21.00.22.907906@aursand.no>

On Thu, 04 Dec 2003 07:28:37 +1100, Edo wrote:
> is there a ready perl function to return the index of a given value in 
> an array?

No.  You have to find it yourself.  Something like this:

  sub in_array {
      my $array = shift;
      my $value = shift;

      my $index = -1;
      foreach ( @$array ) {
          $index++;
          last if ( $_ eq $value );
      }

      return $index;
  }


-- 
Tore Aursand <tore@aursand.no>
"A teacher is never a giver of truth - he is a guide, a pointer to the
 truth that each student must find for himself.  A good teacher is
 merely a catalyst." -- Bruce Lee


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

Date: 3 Dec 2003 21:50:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: return the array index for a given value
Message-Id: <bqllqj$bni$1@mamenchi.zrz.TU-Berlin.DE>

Edo  <eddGallary2@hotmail.com> wrote in comp.lang.perl.misc:
> Edo wrote:
> > Hello
> > is there a ready perl function to return the index of a given value in 
> > an array?

Well, there can't be, because there is no such thing as "the" index
of a given value.  A given value may appear in an array more than once,
or not at all.  In both cases, "the" index is not well defined.

If you are happy to take the first index, and accept an undef if there
isn't one, this would be idiomatic (untested):

    my ( $first_index) = grep $_ eq $value, @array;

It isn't known for efficiency, but may do in a pinch.

A possibly faster solution uses an inverting hash, like so:

    # preparation
    my %invert;
    @invert[ @array] = 0 .. $#array;

    # then
    my $some_index = $invert{ $value};

I leave it up to you to figure out which index gets assigned to a multiple
value.  You could choose another by building %invert differently.

[...]

> by the same way of thinking,

 ...somewhat faulty thinking.

> is there a ready perl function to return a hash slice from a grand hash 
> starting at a given key and covers n numbers of the following sorted keys?

I don't see how that relates to your array-inversion question.  Array
inversion could probably be *used* to solve your next problem, but
as such they are unrelated.

If I get you right, you want a list of n hash keys, which follow some
random element in sorted order.  The hash slice is trivial once you
have this list.

It can be done, to be sure, but it is a rather queer specification.
In particular, it treats the hash as if it had an inherent order.
If you need that, you're better off using the IxHash (I think) or
an equivalent module.

Anno


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

Date: Wed, 3 Dec 2003 16:28:06 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: return the array index for a given value
Message-Id: <slrnbssorm.41s.tadmc@magna.augustmail.com>

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> Edo  <eddGallary2@hotmail.com> wrote in comp.lang.perl.misc:
>> Edo wrote:

>> > is there a ready perl function to return the index of a given value in 
>> > an array?

> If you are happy to take the first index, and accept an undef if there
> isn't one, this would be idiomatic (untested):
                                      ^^^^^^^^
                                      ^^^^^^^^ right :-)

>     my ( $first_index) = grep $_ eq $value, @array;


I think you meant:

    my($first_index) = grep $array[$_] eq $value, 0..$#array;



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


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

Date: Wed, 3 Dec 2003 23:00:51 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: return the array index for a given value
Message-Id: <bqlpv3$aii$1@wisteria.csv.warwick.ac.uk>


anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>     my %invert;
>     @invert[ @array] = 0 .. $#array;

ITYM { } :)

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

Date: 3 Dec 2003 14:25:48 -0800
From: mishq00@yahoo.com (Mohammed Ishaq)
Subject: string matching question.
Message-Id: <6503ea33.0312031425.56565102@posting.google.com>

I have a been trying to do a string match, and the string has []
characters. I do not want perl to treat this a regular expression, but
I cannot get it match. I have the following perl snippet, and the
output of these two searches is different, but I think that both
searches should match successfully.

thanks for any light you can throw.

mi

#!/usr/bin/perl -w

my $e="abcde[12]"; 
my $f="XYZ[12] abcde[12] XYZ[12]";

if ( $f =~ /\b\Q$e\E/ ) { print "match\n"; } else { print "no match\n"
}
if ( $f =~ /\b\Q$e\E\b/ ) { print "match\n"; } else { print "no
match\n" }


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

Date: Wed, 03 Dec 2003 23:39:18 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: string matching question.
Message-Id: <bqlorh$244cim$1@ID-184292.news.uni-berlin.de>

Mohammed Ishaq wrote:
> I have the following perl snippet, and the output of these two
> searches is different, but I think that both searches should match
> successfully.

<snip>

> my $e="abcde[12]"; 
> my $f="XYZ[12] abcde[12] XYZ[12]";
> 
> if ( $f =~ /\b\Q$e\E/ ) { print "match\n"; } else { print "no match\n" }
> if ( $f =~ /\b\Q$e\E\b/ ) { print "match\n"; } else { print "no match\n" }

 From perldoc perlre:
"A word boundary (\b) is a spot between two characters that has a \w
on one side of it and a \W on the other side of it (in either order),
counting the imaginary characters off the beginning and end of the
string as matching a \W."

Since ] is not included in the \w character class, the second of your
regexes does not match.

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



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

Date: Wed, 03 Dec 2003 16:18:57 +0100
From: jon rogers <jon.rogers@tv.tu>
Subject: Useless use of private variable in void context at parser.cgi line 48.
Message-Id: <bql1u1$t28$1@news.gu.se>

Hi,

I keep getting this error message when running my Perl script:

Useless use of private variable in void context at parser.cgi line ...

It is apparently non-fatal as the script executes flawlessly in other
respects. What am I doing wrong?

/ JR



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

Date: 3 Dec 2003 16:43:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Useless use of private variable in void context at parser.cgi line 48.
Message-Id: <bql3qo$ii$1@mamenchi.zrz.TU-Berlin.DE>

jon rogers  <jon.rogers@tv.tu> wrote in comp.lang.perl.misc:
> Hi,
> 
> I keep getting this error message when running my Perl script:
> 
> Useless use of private variable in void context at parser.cgi line ...
> 
> It is apparently non-fatal as the script executes flawlessly in other
> respects. What am I doing wrong?

First off, not showing the line in question.  How can we know what's
wrong if you don't show the code?

If all you want is an explanation of the message, put  "use diagnostics"
near the start of your program, that will elicit an explanatory text to
accompany Perl's messages.

Your program is using a lexical variable (that's what is meant by "private")
in a place where it can do no good.  This is often a sign that Perl
interprets some code differently from what you expect.  You should
correct it.

Anno


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

Date: Wed, 3 Dec 2003 16:31:29 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Useless use of private variable in void context at parser.cgi line 48.
Message-Id: <slrnbssp21.41s.tadmc@magna.augustmail.com>

jon rogers <jon.rogers@tv.tu> wrote:

> Useless use of private variable in void context at parser.cgi line ...

> What am I doing wrong?


Show us "line ..." and we will tell you.


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


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

Date: Wed, 03 Dec 2003 12:28:49 -0500
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: using GD module
Message-Id: <3FCE1D51.8050603@gwu.edu>

Edo wrote:
> #!/usr/local/bin/perl
> use strict;
> use warnings;
> use GD::Graph::lines;
> 
> my @data = (
>             ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
>             [    1,    2,    5,    6,    3,  1.5,    1,     3,     4],
>             [ sort { $a <=> $b } (1, 2, 5, 6, 3, 1.5, 1, 3, 4) ]
>             );
> 
> my $graph = GD::Graph::lines->new(400, 300);
> my $my_graph;
> $graph->set(
>             x_label           => 'X Label',
>             y_label           => 'Y label',
>             title             => 'Some simple graph',
>             y_max_value       => 8,
>             y_tick_number     => 8,
>             y_label_skip      => 2
>             ) or die $my_graph->error;
> 
> my $gd = $my_graph->plot(\@data) or die $my_graph->error;  <--- 23
> 
> Can't call method "plot" on an undefined value at prog/graph line 23.
> 
Well, yeah.  It's complaining that $my_graph is undefined, and sure
enough, you don't define $my_graph anywhere.

            Chris Mattern



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

Date: 3 Dec 2003 10:02:10 -0800
From: james.woodworth@ricardo.com (Jim)
Subject: using xs -- trouble dereferencing
Message-Id: <d1b55932.0312031002.9b5b690@posting.google.com>

Hello,

trying what i thought was going to be straightforward.

a constraint that i am working with is not modifying the C code or the
Perl code; keeping all translation stuff in "xs glue space".  i have
created a small xs file to help me understand this with "simple"
subroutines.

a line such as:
$retval = tryxs( \$num );
when tryxs is a perl routine, i can modify $num by dereferencing with
$$num.  fine.

appearantly, the normal way of allowing $num to be modified in C code
is to _not_ dereference, requiring a change to my perl code. 
therefore, i cannot use XS's & unary operator.

what i have so far for tryxs.xs is:
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "ppport.h"

#include <stdio.h>

MODULE = tryxs          PACKAGE = tryxs

void
tryxs( p )
  SV * p
PREINIT:
  IV j = 0;
  SV * z;
CODE:
  j = SvIV( SvRV( p ));
  j += 1000;
  printf( "num : %d\n", j );
  z = newSViv( j );
OUTPUT:
  p sv_setref_pv( ST(0), Nullch, (void*)z);

what i see:
- "j" does get the scalar sent by perl
- no matter how change the "output" section so far, with various
functions and macros from perlxs, perlguts, and perlapi, $num does not
get the modified value.

i am unsure what combination of macros and functions will allow me to
put the new value on the perl stack.

any ideas out there?

much thanks.


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

Date: Wed, 3 Dec 2003 11:01:59 -0500
From: "Domenico Discepola" <joeminga@yahoo.com>
Subject: Win32::OLE and creation of pivot table in Excel
Message-Id: <sRnzb.114158$PD3.5796620@nnrp1.uunet.ca>

Hello once again.  My goal is to create a pivot table in Excel using data
from an existing worksheet in the current workbook.  The worksheet is called
'Test Worksheet' and the data resides in cells a1:c3.  As I am new to
Win32::OLE, I don't know how to "translate" the following VB Script
(generated from a macro I recorded in Excel) into a "Win32::OLE" / perl
version of those methods:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= "'Test
Worksheet'!R1C1:R2C3").CreatePivotTable TableDestination:="",
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10

ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)

ActiveSheet.Cells(3, 1).Select

Any help would be appreciated.

TIA




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

Date: Wed, 3 Dec 2003 17:05:30 -0000
From: "Ben Liddicott" <ben.liddicott@comodogroup.com>
Subject: Re: Win32::OLE and creation of pivot table in Excel
Message-Id: <bql555$vcc$1@kylie.comodogroup.com>

Hi Domenico,

The ActiveState documentation has some pretty good examples, under =
"Using OLE with Perl", which is in the table of contents under =
"ActivePerl FAQ/Windows Specific".

Try also
    perldoc Win32::OLE

Cheers,
Ben Liddicott


"Domenico Discepola" <joeminga@yahoo.com> wrote in message =
news:sRnzb.114158$PD3.5796620@nnrp1.uunet.ca...
>As I am new to
> Win32::OLE, I don't know how to "translate" the following VB Script
> (generated from a macro I recorded in Excel) into a "Win32::OLE" / =
perl
> version of those methods:




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

Date: Wed, 3 Dec 2003 12:03:46 -0500
From: "Domenico Discepola" <joeminga@yahoo.com>
Subject: Re: Win32::OLE and creation of pivot table in Excel
Message-Id: <mLozb.114173$PD3.5796905@nnrp1.uunet.ca>

>As I am new to
> Win32::OLE, I don't know how to "translate" the following VB Script
> (generated from a macro I recorded in Excel) into a "Win32::OLE" / perl
> version of those methods:
>
> ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= "'Test
> Worksheet'!R1C1:R2C3").CreatePivotTable TableDestination:="",
> TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
>

OK - I read up on "Named Parameters" and found an old post with a concrete
solution to my problem.  I was able to generate the pivot table using the
following code;

$workbook->PivotCaches->Add( {SourceType => 1, SourceData => 'Test
Worksheet!R1C1:R2C3'} )->CreatePivotTable( { TableDestination => "",
TableName => "PivotTable1", DefaultVersion => 1 });

You'll notice that the values of certain named parameters have been replaced
with a number (SourceType and DefaultVersion).  Does anyone know where can I
read more on this (replacement of parameter values with numbers)?

TIA




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

Date: Wed, 03 Dec 2003 18:30:58 +0100
From: Karlheinz Weindl <karlheinz.weindl@oooonlinehome.de>
Subject: Re: Win32::OLE and creation of pivot table in Excel
Message-Id: <bql6lh$8d2$1@online.de>

>  Does anyone know where can I
> read more on this (replacement of parameter values with numbers)?

If you work with Perl under Windows you probably have ActiveState's 
distribution installed. This distribution comes with HTML documentation 
containing an 'OLE Browser' that can be found under 'ActivePerl 
Components / Windows Specific'.
Unfortunately it works only with IE!



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

Date: Wed, 03 Dec 2003 10:21:37 -0600
From: Robert Dover <dover@nortelnetworks.com>
Subject: Re: Your code doesn't work
Message-Id: <bql2g1$ii0$1@zcars0v6.ca.nortel.com>

Colossus wrote:

> Gunnar Hjalmarsson wrote:
> 
>>A suitable starter might be
> 
> What you call suitable is a very difficult
> explanation on how to sort an array of more fields.

Then maybe programming isn't for you?



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

Date: Wed, 03 Dec 2003 20:57:51 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Your code doesn't work
Message-Id: <qtfssv44ahjlcvlm4n8nlg1ho9nuk7p85r@4ax.com>

On Wed, 03 Dec 2003 13:40:13 +0100, Colossus
<colossus_NOSPAM_@freemail.it> wrote:

>@array = ("A00469.PE1 SSGGH.PE1 HBG011318 1.26943 39",
>"A00469.PE1 SGGH2.PE1 HBG011318 1.26943 110",
[snip]

First of all, may you be so kind in the future and quote properly any
post you're answering to? And in case you (really need/want to) change
the subject line, please indicate so (by including e.g. "[was:
something else]").

There's quite a lot of traffic here, and a lot of helpful and
knowlegdeable people too (not me!), but because of the former, the
latter ones need help to help you. This includes giving some
references about what's going one.

For example here I can understand what is *wrong*, but I hardly have a
clue on how to make it *right* wrt what *you want* (but please see
below!).

One nice feature of this NG is that posting guidelines are posted here
regularly to the effect of "helping others to help you". Personally I
don't think it's *necessary* to read them, but surely it can't do
harm! And if someone (one of the helpful and knowlegdeable people!)
took care of writing them, it may well be worth!

> my @sorted = sort { $a->[ 0] cmp $b->[ 0] or $b->[ 4] <=> $a->[ 4] }
>@array;

So your sort routine is designed to sort an AoA by comparing some
fields of the "inner arrays" (yes: I know all this is very imprecise,
but hopefully it will be easier to understand for the OP!).

You're feeding the sort routine *an array of strings* instead! Have
you considered reading

  perldoc -f sort

and

  perldoc -q 'sort an array by'

especially the bit about "Schwartzian Transform"?!? This seems exactly
what you need.

>foreach $indice(0..$#sorted)
>{
>        print $sorted[$indice],"\n";
>}

This portion of code seems rather awkward. Why not use

  #!/usr/bin/perl -l
  #               ^^ if this doesn't "conflict" with anything else!!
  ...
  print for @sorted;

or

  {
    local $\="\n";
    print for @sorted;
  }

or

  {
    local ($\,$,)="\n";
    print @sorted;
  }

instead?

>Output:
[snip]
>That is exactly the same starting array.

The reason is explained above. As I said, I don't really know what you
would like to do. But taking into account what I read above, I can
*guess*, so here's my try; please do *not* complain if that doesn't do
what you expected:

  #!/usr/bin/perl -l
  use strict;
  use warnings;
  
  chomp (my @array = <DATA>);
    
  print for map $_->[0],
    sort { $a->[1] cmp $b->[1] or $b->[2] <=> $a->[2] } map
    [$_, (split)[0,4]], @array;
  __END__
  A00469.PE1 SSGGH.PE1 HBG011318 1.26943 39
  A00469.PE1 SGGH2.PE1 HBG011318 1.26943 110
  A02759.PE1 XLA298150.APP HBG000051 0.12417 592
  A08691.RAP1A AF032713.PE1 HBG009351 0.63293 333
  A08802.PE1 AF349034.PE1 HBG000071 0.82133 386
  A14829.PE1 SSAPOLAI.PE1 HBG004257 1.88791 39
  A14829.PE1 DRAPLIPAI.PE1 HBG004257 1.96625 386
  A14829.PE1 AF042219.PE1 HBG004257 2.03983 110

This gives me:

  A00469.PE1 SGGH2.PE1 HBG011318 1.26943 110
  A00469.PE1 SSGGH.PE1 HBG011318 1.26943 39
  A02759.PE1 XLA298150.APP HBG000051 0.12417 592
  A08691.RAP1A AF032713.PE1 HBG009351 0.63293 333
  A08802.PE1 AF349034.PE1 HBG000071 0.82133 386
  A14829.PE1 DRAPLIPAI.PE1 HBG004257 1.96625 386
  A14829.PE1 AF042219.PE1 HBG004257 2.03983 110
  A14829.PE1 SSAPOLAI.PE1 HBG004257 1.88791 39

Is this what you wanted?!?


HTH,
Michele
-- 
# This prints: Just another Perl hacker,
seek DATA,15,0 and  print   q... <DATA>;
__END__


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

Date: Wed, 3 Dec 2003 16:35:08 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Your code doesn't work
Message-Id: <slrnbssp8s.41s.tadmc@magna.augustmail.com>

Colossus <colossus_NOSPAM_@freemail.it> wrote:

> I think it is much
> better for you not to answer at all. 


I think you have just arranged for a lot of that.

So long.


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


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