[29562] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 806 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 29 21:09:52 2007

Date: Wed, 29 Aug 2007 18:09: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, 29 Aug 2007     Volume: 11 Number: 806

Today's topics:
    Re: "use strict" in a module <ferry.bolhar@chello.at>
    Re: "use strict" in a module <ben@morrow.me.uk>
        Appending a character to a field  bokjasong@gmail.com
    Re: Appending a character to a field <simon.chao@fmr.com>
    Re: Appending a character to a field <jurgenex@hotmail.com>
    Re: Appending a character to a field <ben@morrow.me.uk>
    Re: Mac: Perl script that will run when double-clicked <anno4000@mailbox.zrz.tu-berlin.de>
        REINSTALL PERL <jorg_reyes@hotmail.com>
    Re: REINSTALL PERL xhoster@gmail.com
        Searching in a line <lerameur@yahoo.com>
    Re: Searching in a line <simon.chao@fmr.com>
    Re: Searching in a line <jurgenex@hotmail.com>
    Re: Searching in a line <lerameur@yahoo.com>
    Re: Searching in a line <jurgenex@hotmail.com>
    Re: Searching in a line <jurgenex@hotmail.com>
        why warn on undefined $1? <ihok@hotmail.com>
    Re: why warn on undefined $1? xhoster@gmail.com
    Re: why warn on undefined $1? <wahab@chemie.uni-halle.de>
    Re: why warn on undefined $1? <ihok@hotmail.com>
    Re: why warn on undefined $1? <ben@morrow.me.uk>
    Re: why warn on undefined $1? <ihok@hotmail.com>
    Re: why warn on undefined $1? <noreply@gunnar.cc>
    Re: why warn on undefined $1? <ihok@hotmail.com>
    Re: why warn on undefined $1? <noreply@gunnar.cc>
        win32::sqlserver not able to sql_insert <michel.knight@cgi.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 29 Aug 2007 22:29:04 +0200
From: "Ferry Bolhar" <ferry.bolhar@chello.at>
Subject: Re: "use strict" in a module
Message-Id: <44aa$46d5d714$54718838$890@news.chello.at>

Larry:

>    use strict;
>    use Exporter ();
>    use vars qw/@ISA @EXPORT/;
>    @ISA = qw/Exporter/;
>    @EXPORT = qw/$x $y $z/;
>    use vars @EXPORT;
>
>    $x = 5;
>
> produces:
>
>    Global symbol "$x" requires explicit package name at FooPkg.pm
> line 10.
>    FooPkg.pm had compilation errors.
>
> However, if I change:
>
>    use vars @EXPORT;
>
> to
>
>    use vars qw/$x $y $z/;
>
> it works. But I would like to avoid repeating the qw/$x $y $z/ .  Why
> won't the original version work?

Because "use" is a _compiler_ directive, processed much earlier that the
assignment to @EXPORT which gets executed at _run-time_. When
the

use vars @EXPORT;

is processed (and the resultant module code gets executed), @EXPORT
doesn't yet contain any variable names, so the "use vars" has nothing to do
(similar to a "use vars;").

One could write

BEGIN {
  @EXPORT = qw/$x $y $z/;
}
use vars @EXPORT;

and it should work as expected, but I'd avoid code techniques like this,
because it makes your code harder to read.

Greetings, Ferry
--





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

Date: Wed, 29 Aug 2007 23:29:13 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: "use strict" in a module
Message-Id: <pi8hq4-qve.ln1@osiris.mauzo.dyndns.org>


Quoth Larry <larry.grant.dc@gmail.com>:
> The following code:
> 
>     package FooPkg;
> 
>     use strict;
>     use Exporter ();
>     use vars qw/@ISA @EXPORT/;
>     @ISA = qw/Exporter/;
>     @EXPORT = qw/$x $y $z/;
>     use vars @EXPORT;
> 
>     $x = 5;
> 
> produces:
> 
>     Global symbol "$x" requires explicit package name at FooPkg.pm
> line 10.
>     FooPkg.pm had compilation errors.
> 
> However, if I change:
> 
>     use vars @EXPORT;
> 
> to
> 
>     use vars qw/$x $y $z/;
> 
> it works. But I would like to avoid repeating the qw/$x $y $z/ .  Why
> won't the original version work?

As has been explained, you would need to assign to @EXPORT at compile
time. There is a pragma on CPAN, vars::i, which will do this for you, so
you could say

    use vars::i '@EXPORT' => qw/$x $y $z/;
    use vars @EXPORT;

but in any case 'use vars' is considered bad style nowadays (since perl
5.6). The currently recommended way to write the above would be

    use strict;

    use Exporter ();
    our @ISA = qw/Exporter/;

    our ($x, $y, $z);
    our @EXPORT = qw/$x, $y, $z/;

which still leaves you repeating the list of variables... consider it a
'tax' on exporting things. You should not export (especially variables)
without good reason :).

(Note that in the presence of subsequent 'package' statements, the
behaviour of 'our' is not quite the same as that of 'use vars'. For
instance, given

    package A;
    our $foo;

    package B;
    print $foo;

$foo refers to $A::foo, not $B::foo.)

Ben



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

Date: Wed, 29 Aug 2007 20:22:31 -0000
From:  bokjasong@gmail.com
Subject: Appending a character to a field
Message-Id: <1188418951.537913.123910@x35g2000prf.googlegroups.com>



Hi,


I'm a perl newbie and would like to ask this question.

Let's say I have the following code. Trying to check the disk space,
it's to truncate the percent sign % from the df -k output, compare the
percentage field to see if it's bigger than 90%, and grasp only those
lines that are and push those to an array @df. But how can I add the
percentage sign back to the percentage field on each line for the
proper output? I put down ??????? as below to find out what regexp
needs to be there in the below.


$percent=90;

open(DFOUT, "/usr/bin/df -k|");
while (<DFOUT>) {
        next if ($_ =~ /Filesystem/i);
        s/\%//;            # to remove the percent sign for comparison
        if ( (split)[4] >= $percent ) {
                ???????
                push(@df, $_);
        }
}

print "@dfoutput\n";



I appreciate your help very much!

Thank you.


- Bok



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

Date: Wed, 29 Aug 2007 20:39:15 -0000
From:  it_says_BALLS_on_your forehead <simon.chao@fmr.com>
Subject: Re: Appending a character to a field
Message-Id: <1188419955.802662.220740@d55g2000hsg.googlegroups.com>

On Aug 29, 4:22 pm, bokjas...@gmail.com wrote:
> Hi,
>
> I'm a perl newbie and would like to ask this question.
>
> Let's say I have the following code. Trying to check the disk space,
> it's to truncate the percent sign % from the df -k output, compare the
> percentage field to see if it's bigger than 90%, and grasp only those
> lines that are and push those to an array @df. But how can I add the
> percentage sign back to the percentage field on each line for the
> proper output? I put down ??????? as below to find out what regexp
> needs to be there in the below.
>
> $percent=90;
>
> open(DFOUT, "/usr/bin/df -k|");
> while (<DFOUT>) {
>         next if ($_ =~ /Filesystem/i);
>         s/\%//;            # to remove the percent sign for comparison
>         if ( (split)[4] >= $percent ) {
>                 ???????
>                 push(@df, $_);
>         }
>
> }
>
> print "@dfoutput\n";

How about instead of removing the '%' sign in the first place, you
pass a copy of (split)[4] as a parameter to a subroutine, then chop it
off there to do your compare, and return true or false from the
subroutine to determine whether or not you should push into your @df
array?



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

Date: Wed, 29 Aug 2007 21:24:37 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Appending a character to a field
Message-Id: <pulBi.1390$J65.170@trndny08>

bokjasong@gmail.com wrote:
> Hi,
>
>
> I'm a perl newbie and would like to ask this question.
>
> Let's say I have the following code. Trying to check the disk space,
> it's to truncate the percent sign % from the df -k output, compare the
> percentage field to see if it's bigger than 90%, and grasp only those
> lines that are and push those to an array @df. But how can I add the
> percentage sign back to the percentage field on each line for the
> proper output? I put down ??????? as below to find out what regexp
> needs to be there in the below.

Just plain ignore the % sign. When evaluating a text in numerical context 
then Perl will take any leading number as the value and happily ignore any 
trailing non-numbers (somewhat simplified, but shouldn't matter in your 
case).

> $percent=90;
> open(DFOUT, "/usr/bin/df -k|");
> while (<DFOUT>) {
>        next if ($_ =~ /Filesystem/i);
>        s/\%//;            # to remove the percent sign for comparison

Just get rid of this substitute line.

>        if ( (split)[4] >= $percent ) {

Then this comparison should work just automagically.

jue 




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

Date: Wed, 29 Aug 2007 23:15:48 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Appending a character to a field
Message-Id: <kp7hq4-qve.ln1@osiris.mauzo.dyndns.org>


Quoth "Jürgen Exner" <jurgenex@hotmail.com>:
> bokjasong@gmail.com wrote:
> >
> > Let's say I have the following code. Trying to check the disk space,
> > it's to truncate the percent sign % from the df -k output, compare the
> > percentage field to see if it's bigger than 90%, and grasp only those
> > lines that are and push those to an array @df. But how can I add the
> > percentage sign back to the percentage field on each line for the
> > proper output? I put down ??????? as below to find out what regexp
> > needs to be there in the below.
> 
> Just plain ignore the % sign. When evaluating a text in numerical context 
> then Perl will take any leading number as the value and happily ignore any 
> trailing non-numbers (somewhat simplified, but shouldn't matter in your 
> case).

This ignores the fact that Perl will warn if a string has trailing
non-numeric characters. This warning can be suppressed for a block with

    no warnings 'numeric';

> > $percent=90;
> > open(DFOUT, "/usr/bin/df -k|");

You should always check the return value of open.
You should probably use lexical filehandles.
You should probably use 3-arg open, as its safer.

    open(my $DFOUT, '-|', '/usr/bin/df', '-k')
        or die "cannot run df: $!";

> > while (<DFOUT>) {
> >        next if ($_ =~ /Filesystem/i);

$_ is implicitly used by the match operators, so

    next if /Filesystem/i;

> >        s/\%//;            # to remove the percent sign for comparison
> 
> Just get rid of this substitute line.
> 
> >        if ( (split)[4] >= $percent ) {
> 
> Then this comparison should work just automagically.

To add the % back on, the simplest means is to push "$_%" onto your
array instead of $_. A better answer may be to use the Filesys::Df or
Filesys::DfPortable module, and get the information straight from
statvfs(2) without needing to invoke df(1).

Ben



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

Date: Wed, 29 Aug 2007 23:54:01 +0200
From: Anno Siegel <anno4000@mailbox.zrz.tu-berlin.de>
Subject: Re: Mac: Perl script that will run when double-clicked
Message-Id: <5jm87pFabrmU1@mid.dfncis.de>

On 2007-08-29 06:17:58 +0200, amirkarger@gmail.com said:

> On Aug 22, 1:28 pm, amirkar...@gmail.com wrote:
> 1) You need to chmod +x the script, or it won't run. Which sort of
> defeats the purpose of creating a double-clickable program, doesn't
> it?

How so?  What do you consider the purpose of making a perl script clickable?

Anno



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

Date: Wed, 29 Aug 2007 16:29:18 -0700
From:  Jorge Reyes <jorg_reyes@hotmail.com>
Subject: REINSTALL PERL
Message-Id: <1188430158.635171.12960@w3g2000hsg.googlegroups.com>

ok so now i am really desperate because i cannot resolve the problem
related with the error message:

Can't locate object method "new" via package "URI" (perhaps you forgot
to load "URI"?) at /usr/perl5/5.6.1/lib/HTTP/Request.pm line 82

so then now i want to know how can i reinstall all the perl, i am
working in a sunOs 5.9 which perl version is 5.6.1 and it doesnt have
internet connection (i think that this problem could be fixed, i
hope), this is because i dont understand why this error still
happening, i try to reinstall all the SOAP and many other modules that
the same system ask to me, but nothing, so please help me, how can i
reinstall perl?



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

Date: 30 Aug 2007 00:24:18 GMT
From: xhoster@gmail.com
Subject: Re: REINSTALL PERL
Message-Id: <20070829202421.145$Xw@newsreader.com>

Jorge Reyes <jorg_reyes@hotmail.com> wrote:
> ok so now i am really desperate because i cannot resolve the problem
> related with the error message:
>
> Can't locate object method "new" via package "URI" (perhaps you forgot
> to load "URI"?) at /usr/perl5/5.6.1/lib/HTTP/Request.pm line 82
>
> so then now i want to know how can i reinstall all the perl, i am
> working in a sunOs 5.9 which perl version is 5.6.1 and it doesnt have
> internet connection (i think that this problem could be fixed, i
> hope), this is because i dont understand why this error still
> happening, i try to reinstall all the SOAP and many other modules that
> the same system ask to me, but nothing, so please help me, how can i
> reinstall perl?

Download the source tar-ball from cpan.org, transfer it to your computer
without the network connection, and read the README file, and do what it
says.

But be advised that desperation rarely actually solves problems.

Instead, I'd made sure the directory where SOAP::Lite is installed is
first in your @INC.  If that didn't work, dump %INC to see what all modules
you have loaded.  Then I'd profile the code with -d:DProf, then
dump the call tree with dprofpp -T and trace back is calling HTTP::Request.

Xho

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


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

Date: Wed, 29 Aug 2007 13:45:47 -0700
From:  lerameur <lerameur@yahoo.com>
Subject: Searching in a line
Message-Id: <1188420347.833344.71350@w3g2000hsg.googlegroups.com>

Hello all,

I want to do a search in a log file. each line has the following
pattern:
34,56,,9,0,0,,,,65;
So there 10 section. How do I parse through different sections?
meaning I want section 4, which is the number 9

thanks
ken



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

Date: Wed, 29 Aug 2007 20:51:40 -0000
From:  it_says_BALLS_on_your forehead <simon.chao@fmr.com>
Subject: Re: Searching in a line
Message-Id: <1188420700.972424.27120@r34g2000hsd.googlegroups.com>

On Aug 29, 4:45 pm, lerameur <leram...@yahoo.com> wrote:
> Hello all,
>
> I want to do a search in a log file. each line has the following
> pattern:
> 34,56,,9,0,0,,,,65;
> So there 10 section. How do I parse through different sections?
> meaning I want section 4, which is the number 9

if every possible value within a 'section' cannot contain a comma ',',
then you can just split on a comma, and take the 4th section.

my $log = 'log.txt';
open my $fh, '<', $log or die "can't open '$log': $!\n";
while ( <$fh> ) {
    my $val = (split /,/)[3];
    print $val, "\n";
}
close $fh;



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

Date: Wed, 29 Aug 2007 21:25:47 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Searching in a line
Message-Id: <vvlBi.1854$Pa5.596@trndny09>

lerameur wrote:
> Hello all,
>
> I want to do a search in a log file. each line has the following
> pattern:
> 34,56,,9,0,0,,,,65;
> So there 10 section. How do I parse through different sections?

perldoc -f split

> meaning I want section 4, which is the number 9

$sec4 = split($value)[3]

jue 




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

Date: Wed, 29 Aug 2007 14:37:03 -0700
From:  lerameur <lerameur@yahoo.com>
Subject: Re: Searching in a line
Message-Id: <1188423423.397042.217540@r29g2000hsg.googlegroups.com>

On Aug 29, 5:25 pm, "J=FCrgen Exner" <jurge...@hotmail.com> wrote:
> lerameur wrote:
> > Hello all,
>
> > I want to do a search in a log file. each line has the following
> > pattern:
> > 34,56,,9,0,0,,,,65;
> > So there 10 section. How do I parse through different sections?
>
> perldoc -f split
>
> > meaning I want section 4, which is the number 9
>
> $sec4 =3D split($value)[3]
>
> jue


Hi
either way  I am getting these error messages:
 ./spam2: my: command not found
 ./spam2: line 6: unexpected EOF while looking for matching `"'
 ./spam2: line 10: syntax error: unexpected end of file

ken



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

Date: Wed, 29 Aug 2007 21:50:35 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Searching in a line
Message-Id: <LSlBi.2046$Pa5.35@trndny09>

lerameur wrote:
> On Aug 29, 5:25 pm, "Jürgen Exner" <jurge...@hotmail.com> wrote:
>> lerameur wrote:
>>> I want to do a search in a log file. each line has the following
>>> pattern:
>>> 34,56,,9,0,0,,,,65;
>>> So there 10 section. How do I parse through different sections?
>>
>> perldoc -f split
>>
>>> meaning I want section 4, which is the number 9
>>
>> $sec4 = split($value)[3]
>
> either way  I am getting these error messages:
> ./spam2: my: command not found
> ./spam2: line 6: unexpected EOF while looking for matching `"'
> ./spam2: line 10: syntax error: unexpected end of file

Ok, ok, that split() syntax is not correct, I forgot to specify the pattern. 
If you had included a self-contained minimal program then I could have 
tested my suggestion and that would not have happened.

As for the other error messages: you didn't show us your program, therefore 
there is no way for us to see what is wrong. Have you read the posting 
guidelines that are posted here frequently?

jue





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

Date: Wed, 29 Aug 2007 22:00:27 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Searching in a line
Message-Id: <%%lBi.595$Lz5.238@trndny04>

Jürgen Exner wrote:
> lerameur wrote:
>> On Aug 29, 5:25 pm, "Jürgen Exner" <jurge...@hotmail.com> wrote:
>>> lerameur wrote:
>>>> I want to do a search in a log file. each line has the following
>>>> pattern:
>>>> 34,56,,9,0,0,,,,65;
>>>> So there 10 section. How do I parse through different sections?

> Ok, ok, that split() syntax is not correct, I forgot to specify the
> pattern. If you had included a self-contained minimal program then I
> could have tested my suggestion and that would not have happened.

Here's the spoonfed version:

my $foo = '34,56,,9,0,0,,,,65';
my $bar = (split(/,/,$foo))[3];
print $bar;

jue 




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

Date: Wed, 29 Aug 2007 20:49:07 -0000
From:  "ihok@hotmail.com" <ihok@hotmail.com>
Subject: why warn on undefined $1?
Message-Id: <1188420547.961572.47740@o80g2000hse.googlegroups.com>

Consider:

# colors -> colours
	$token = 'colors';
	$token =~ s/or(ed|ing|s)?$/our$1/;

But if $token == 'color', Perl emits a warning: Use of uninitialized
value in concatenation (.) or string. True enough, $1 is undefined,
but why bother warning? I mean, my regexp has a '?' in it because I
expect that sometimes 'color' will not have an ending.

I suspect that the answer is "it's simpler to just warn whenever an
undefined variable occurs in a string, and it's just not worth it to
detect the case when such a warning is vacuous. Try 'no warnings'.' I
can deal with that.



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

Date: 29 Aug 2007 21:01:43 GMT
From: xhoster@gmail.com
Subject: Re: why warn on undefined $1?
Message-Id: <20070829170146.225$YW@newsreader.com>

"ihok@hotmail.com" <ihok@hotmail.com> wrote:
> Consider:
>
> # colors -> colours
>         $token = 'colors';
>         $token =~ s/or(ed|ing|s)?$/our$1/;
>
> But if $token == 'color', Perl emits a warning: Use of uninitialized
> value in concatenation (.) or string. True enough, $1 is undefined,
> but why bother warning? I mean, my regexp has a '?' in it because I
> expect that sometimes 'color' will not have an ending.

There are limits to DWIM.  Perl doesn't know why you stuck the ? in, so
it can't tailor its behavior to this unknown motivation.

> I suspect that the answer is "it's simpler to just warn whenever an
> undefined variable occurs in a string, and it's just not worth it to
> detect the case when such a warning is vacuous. Try 'no warnings'.' I
> can deal with that.

You can do that, but I think it would make more sense to change your regex
to explicitly let it match and capture the empty string:

s/or(ed|ing|s|)$/our$1/

Xho

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


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

Date: Wed, 29 Aug 2007 23:13:59 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: why warn on undefined $1?
Message-Id: <fb4nim$1gun$1@nserver.hrz.tu-freiberg.de>

ihok@hotmail.com wrote:
> Consider:
> 
> # colors -> colours
> 	$token = 'colors';
> 	$token =~ s/or(ed|ing|s)?$/our$1/;
> 
> But if $token == 'color', Perl emits a warning: Use of uninitialized
> value in concatenation (.) or string. True enough, $1 is undefined,
> but why bother warning? I mean, my regexp has a '?' in it because I
> expect that sometimes 'color' will not have an ending.

xhoster did already point to a solution,
but you could also be more explicit about
your search term, e.g.

   my $token = 'color';
   $token =~ s/ \B or(ed | ing | s | $)? /our$1/x;

by simply putting the $ (or a \b) into the
capturing parenthesis. I added another \B
in front of the term in order to make
clear that we start the search in the
middle of a word.




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

Date: Wed, 29 Aug 2007 21:17:15 -0000
From:  "ihok@hotmail.com" <ihok@hotmail.com>
Subject: Re: why warn on undefined $1?
Message-Id: <1188422235.307680.44810@d55g2000hsg.googlegroups.com>

On Aug 29, 5:01 pm, xhos...@gmail.com wrote:
>
> You can do that, but I think it would make more sense to change your regex
> to explicitly let it match and capture the empty string:
>
> s/or(ed|ing|s|)$/our$1/

Bingo! I didn't know you could do that. Thanks!



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

Date: Thu, 30 Aug 2007 00:01:51 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: why warn on undefined $1?
Message-Id: <vfahq4-i241.ln1@osiris.mauzo.dyndns.org>


Quoth xhoster@gmail.com:
> "ihok@hotmail.com" <ihok@hotmail.com> wrote:
> > Consider:
> >
> > # colors -> colours
> >         $token = 'colors';
> >         $token =~ s/or(ed|ing|s)?$/our$1/;
> >
> > But if $token == 'color', Perl emits a warning: Use of uninitialized
> > value in concatenation (.) or string. True enough, $1 is undefined,
> > but why bother warning? I mean, my regexp has a '?' in it because I
> > expect that sometimes 'color' will not have an ending.
> 
> There are limits to DWIM.  Perl doesn't know why you stuck the ? in, so
> it can't tailor its behavior to this unknown motivation.
> 
> > I suspect that the answer is "it's simpler to just warn whenever an
> > undefined variable occurs in a string, and it's just not worth it to
> > detect the case when such a warning is vacuous. Try 'no warnings'.' I
> > can deal with that.
> 
> You can do that, but I think it would make more sense to change your regex
> to explicitly let it match and capture the empty string:
> 
> s/or(ed|ing|s|)$/our$1/

Or (better IMHO), use look-around assertions:

    my $str = 'color colored tricolor floor';
    $str =~ s/ (?<= col) or (?= (?: ed|ing|s)? \b) /our/gx;
    print $str;
    # colour coloured tricolour floor

Ben


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

Date: Wed, 29 Aug 2007 23:11:01 -0000
From:  "ihok@hotmail.com" <ihok@hotmail.com>
Subject: Re: why warn on undefined $1?
Message-Id: <1188429061.510661.196550@o80g2000hse.googlegroups.com>

On Aug 29, 7:01 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Or (better IMHO), use look-around assertions:
>
>     my $str = 'color colored tricolor floor';
>     $str =~ s/ (?<= col) or (?= (?: ed|ing|s)? \b) /our/gx;
>     print $str;
>     # colour coloured tricolour floor

Whoa. That's heavy.

Next question: how can I store the s/// regexp in a variable? I want
something like qr//, but for s///. In other words, I want this to
work, but it doesn't.

my $re = s/or(ed|ing|s)?$/our$1/;
my $s = 'colored';
$s =~ $re;
print $s;
# coloured



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

Date: Thu, 30 Aug 2007 01:33:12 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: why warn on undefined $1?
Message-Id: <5jme1sFb7n5U1@mid.individual.net>

ihok@hotmail.com wrote:
> how can I store the s/// regexp in a variable? I want
> something like qr//, but for s///. In other words, I want this to
> work, but it doesn't.
> 
> my $re = s/or(ed|ing|s)?$/our$1/;

     my $re = 's/or(ed|ing|s)?$/our$1/';

> my $s = 'colored';
> $s =~ $re;

     eval "\$s =~ $re";

> print $s;
> # coloured

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


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

Date: Wed, 29 Aug 2007 23:57:44 -0000
From:  "ihok@hotmail.com" <ihok@hotmail.com>
Subject: Re: why warn on undefined $1?
Message-Id: <1188431864.378752.29960@r34g2000hsd.googlegroups.com>

On Aug 29, 7:33 pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> i...@hotmail.com wrote:
> > how can I store the s/// regexp in a variable? I want
> > something like qr//, but for s///. In other words, I want this to
> > work, but it doesn't.
>
> > my $re = s/or(ed|ing|s)?$/our$1/;
>
>      my $re = 's/or(ed|ing|s)?$/our$1/';
>
> > my $s = 'colored';
> > $s =~ $re;
>
>      eval "\$s =~ $re";
>
> > print $s;
> > # coloured

Awesome. Is there any way to precompile the $re, as qr// would do?



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

Date: Thu, 30 Aug 2007 02:12:07 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: why warn on undefined $1?
Message-Id: <5jmgarFbdv4U1@mid.individual.net>

ihok@hotmail.com wrote:
> On Aug 29, 7:33 pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
>> i...@hotmail.com wrote:
>>> how can I store the s/// regexp in a variable? I want
>>> something like qr//, but for s///. In other words, I want this to
>>> work, but it doesn't.
>>> my $re = s/or(ed|ing|s)?$/our$1/;
>>      my $re = 's/or(ed|ing|s)?$/our$1/';
>>
>>> my $s = 'colored';
>>> $s =~ $re;
>>      eval "\$s =~ $re";
>>
>>> print $s;
>>> # coloured
> 
> Awesome. Is there any way to precompile the $re, as qr// would do?

This is all I can think of:

     my $re = qr/or(ed|ing|s)?$/;
     my $s = 'colored';
     $s =~ s/$re/our$1/;

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


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

Date: Wed, 29 Aug 2007 15:16:21 -0700
From:  Digger <michel.knight@cgi.com>
Subject: win32::sqlserver not able to sql_insert
Message-Id: <1188425781.914607.77670@19g2000hsx.googlegroups.com>

Hi,
I hope that anybody have info on this, i've install and have
win32::sqlserver working properly.
I'm able to retrieve data from my database with the select statement.

My problem is with sql_insert here my code:

my $table = "icon";
#my %values=("iconID"=>'3',"link"=>"something");
#my %values=("iconID"=>3,"link"=>"something");
#my %values=("iconID"=>"3","link","something");
#my %values=("iconID",3,"link","something");
my %values=("iconID","3","link","somethingElse");

$sqlsrv->sql_insert($table,\%values);

Table is call icon, iconID is a primary key and an integer, link is a
varchar.

Here the error I get all the time:
SQL Server message 515, Severity 16, State 2, Server WEB-T-
SQL1\DVSQBQL
Line 1
Cannot insert the value NULL into column 'iconid', table
'master.dbo.Icon'; column does not allow nulls. INSERT fails.
    1> EXEC sp_executesql N'INSERT icon (iconID, link)
    2>    VALUES (@P1, @P2)',
    3>      N'@P1 int, @P2 varchar(13)',
    4>      @P1 = NULL, @P2 = 'somethingElse'
The statement has been terminated.

It look like it doesn't like my value for IconID, what's missing...
take me out of my misery.

Thx,

Michel



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

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


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