[28635] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9999 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 23 03:05:50 2006

Date: Thu, 23 Nov 2006 00:05:08 -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           Thu, 23 Nov 2006     Volume: 10 Number: 9999

Today's topics:
    Re: Embedding perl in shared libs <benmorrow@tiscali.co.uk>
    Re: Export module <benmorrow@tiscali.co.uk>
    Re: Extracting Date using Regular Expressions <shafa.fahad@gmail.com>
    Re: Extracting Date using Regular Expressions <john@castleamber.com>
    Re: FAQ 6.19 What good is "\G" in a regular expression? <rvtol+news@isolution.nl>
    Re: FAQ 6.19 What good is "\G" in a regular expression? <tbmoore9@verizon.net>
    Re: FAQ 6.19 What good is "\G" in a regular expression? <benmorrow@tiscali.co.uk>
    Re: FAQ 6.19 What good is "\G" in a regular expression? <brian.d.foy@gmail.com>
    Re: FAQ 7.15 How do I create a static variable? <tbmoore9@verizon.net>
        File open problem <balaji.draj@gmail.com>
    Re: File open problem <damercer@comcast.net>
    Re: File open problem <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: generic increment of number/string <benmorrow@tiscali.co.uk>
    Re: How to change Perl's concept of a newline in regexp <benmorrow@tiscali.co.uk>
        Is a file in use? <steviehaston@hotmail.com>
    Re: Is a file in use? xhoster@gmail.com
    Re: Is a file in use? <vilain@spamcop.net>
        new CPAN modules on Thu Nov 23 2006 (Randal Schwartz)
    Re: Regex exactly 0, 1 or 2 matches, {0,2} not working <benmorrow@tiscali.co.uk>
    Re: Stuff a hash from two source files <mtbr0228AT@sbcglobalDOT.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 22 Nov 2006 21:37:52 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Embedding perl in shared libs
Message-Id: <gise34-v0c.ln1@osiris.mauzo.dyndns.org>


Quoth Bastian Friedrich <usenet-nov-06@bastian-friedrich.de>:
> Hi,
> 
> I am currently working on a project that uses the "perlembed" methods to run
> perl functions from within a C program. The structure is similar to
> Apache's "mod_perl":
> 
> Program A loads my library B with the "dlopen" POSIX system call. Library B
> is linked against Perl (-lperl /path/to/Dynaloader.a). Library B
> initializes a Perl interpreter C that parses a script D. In this script,
> there are "use" statements for modules that in turn need binary extensions.
> Perl itself uses the "dlopen" call itself to load these extensions.
> 
> dlopen takes two parameters: file path, and flags.
> 
> * When the first dlopen call (A -> B) is done _without_ "RTLD_GLOBAL"
>   flag, a segfault occurs during the parsing of the script.
> * When linking program A with perl, everything is fine
> * When using the RTLD_GLOBAL flag, everything is fine
> * When script D does not load binary extensions, everything is fine.
> * When statically linking library B to program A (instead of dlopening it),
>   everything is fine.
> 
> Obviously, there is some problem with the dlopen calls :((
> 
> If you are interested in the topic, you can download a sample program from
> http://www.iump.de/perl_via_dlopen.tar.gz
> 
> So my questions are:
> * Is this behaviour "normal"? Is RTLD_GLOBAL in fact absolutely necessary in
>   that place?

It seems pretty clear to me from dlopen(3):

| Optionally,  RTLD_GLOBAL  may  be  or'ed  into  flag, in which case the
| external symbols defined in the library will be made available for sym-
| bol  resolution  of  subsequently  loaded  libraries.

That is, unless you use RTLD_GLOBAL, the symbols from -lperl (which were
pulled in either from or by libB.so, depending on whether libB is
statically or dynamically linked to libperl) won't be available to the
dynamically loaded extensions later. Since they require those symbols,
you get a segfault.

> * Did I really hit a perl bug??

Nope.

> * Do you know about any workarounds?

Use RTLD_GLOBAL. Is this a problem? If, for some reason, you really
don't want to load libB.so with RTLD_GLOBAL, then I guess that you could

    1. build a shared libperl.so (to do this you need to rebuild perl
    with -Duseshrplib),

    2. *don't* link libB with -lperl, but instead

    3. dlopen libperl.so from B with RTLD_GLOBAL.

Of course you would then have to dlsym perl_parse &c., and you may well
have *real* trouble getting the macros in EXTERN.h to behave. So you'd
be better off creating separate libBperl.so and libBrtld_local.so, and
having one dlopen the other.
    
Ben

-- 
   If you put all the prophets,   |   You'd have so much more reason
   Mystics and saints             |   Than ever was born
   In one room together,          |   Out of all of the conflicts of time.
benmorrow@tiscali.co.uk                             The Levellers, 'Believers'


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

Date: Wed, 22 Nov 2006 22:48:56 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Export module
Message-Id: <on0f34-7ks.ln1@osiris.mauzo.dyndns.org>


Quoth anno4000@radom.zrz.tu-berlin.de:
>  <hristov.milen@gmail.com> wrote in comp.lang.perl.misc:
> > Hi,
> > I have a module, that I require in some script.
> > 
> > How can I require another module, inside mine and make it global.
> > 
> > For example, if I have in my Some.pm -> 'use strict'
> > how can I make the strict global, without require it in the main script
> > ?
> 
> You can't.  "strict" is lexically scoped and a file is a maximal lexical
> scope.

use Acme::use::strict::with::pride;

(sorry; someone had to point it out, though :) )

Ben

[Just in case the OP doesn't realise: this module is a joke. It is not
meant for serious use.]

-- 
                Outside of a dog, a book is a man's best friend.
                Inside of a dog, it's too dark to read.
benmorrow@tiscali.co.uk                                           Groucho Marx


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

Date: 22 Nov 2006 21:02:39 -0800
From: "Kimi" <shafa.fahad@gmail.com>
Subject: Re: Extracting Date using Regular Expressions
Message-Id: <1164258158.819241.154360@b28g2000cwb.googlegroups.com>


Paul Lalli wrote:
> John W. Krahn wrote:
> > Kimi wrote:
> > > I have a string "Tue Nov  7 14:04:16 2006: Unable to open prev pos
> > > file" in a variable "myvariable" and I need to extract "Tue Nov 7
> > > 14:14:16 2006" to another variable..
> > >
> > > I also would like to know if there are any way to compare the above
> > > result with Current date and find the difference of days/months
> >
> >
> > $ perl -le'
> > use POSIX q/mktime/;
> >
> > my $myvariable = "Tue Nov  7 14:04:16 2006: Unable to open prev pos file";
> >
> > my $week_day = qr/Mon|Tue|Wed|Thu|Fri|Sat|Sun/;
> > my $mon_name = qr/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/;
> >
> > my ( $mon, $day, $hour, $min, $sec, $year ) = $myvariable =~ /$week_day \s+
> > ($mon_name) \s+ (\d+) \s+ (\d+) : (\d+) : (\d+) \s+ (\d+)/x;
> >
> > print "$sec, $min, $hour, $day, $mon, $year";
> >
> > my $old_date = mktime $sec, $min, $hour, $day, ( index( $mon_name, $mon ) -
> > index( $mon_name, q/Jan/ ) ) / 4, $year - 1900;
> >
> > my $current_date = time;
> >
> > my ( $diff_days, $diff_mons ) = ( gmtime $current_date - $old_date )[ 3, 4 ];
> >
> > print for scalar localtime $old_date, scalar localtime $current_date, "Days:
> > $diff_days, Months: $diff_mons";
> > '
> > 16, 04, 14, 7, Nov, 2006
> > Tue Nov  7 14:04:16 2006
> > Wed Nov 22 05:48:51 2006
> > Days: 15, Months: 0
>
> Or, if you didn't feel like doing all that work yourself, take
> advantage of modules on CPAN, like Date::Manip...
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Date::Manip;
>
> my $var = "Tue Nov  7 14:04:16 2006: Unable to open prev pos file";
> my ($dttm) = ($var =~ /^(.*\d{4}):/);
> my $date = ParseDate($dttm);
> die "Couldn't parse date!\n" unless $date;
> my $today = ParseDate("today");
> my ($Y, $M, $W, $D, $h, $m, $s) =
>    (DateCalc($date, $today, \my $err, 1) =~ /\d+/g
> );
> print "Date was $Y year(s), $M month(s), $W week(s), $D day(s), $h
> hour(s), $m minute(s) and $s second(s) ago\n";
> __END__
> Date was 0 year(s), 0 month(s), 2 week(s), 1 day(s), 0 hour(s), 47
> minute(s) and 0 second(s) ago
>
>
> Paul Lalli


Thanks Paul for your help, I tried running the script in my PC, but it
says "Can't locate Date/Manip.pm in @INC (@INC contains:
/System/Library/Perl/5.8.6/darwin-thread-multi-2level
/System/Library/Perl/5.8.6
/Library/Perl/5.8.6/darwin-thread-multi-2level /Library/Perl/5.8.6
/Library/Perl /Network/Library/Perl/5.8.6/darwin-thread-multi-2level
/Network/Library/Perl/5.8.6 /Network/Library/Perl
/System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.8.6 /Library/Perl/5.8.1 .) at datefind
line 4.
BEGIN failed--compilation aborted at datefind line 4."

So the system couldn't find manip.pm. Currently i am using 5.8.6 in mac
OS X. Would appreciate your help if I can get to know what could be the
solution for it...

Thanks in advance,
Kimi



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

Date: 23 Nov 2006 06:03:56 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Extracting Date using Regular Expressions
Message-Id: <Xns9884AA5F6A0castleamber@130.133.1.4>

"Kimi" <shafa.fahad@gmail.com> wrote:


> Thanks Paul for your help, I tried running the script in my PC, but it
> says "Can't locate Date/Manip.pm in @INC (@INC contains:

Install it via CPAN.

> So the system couldn't find manip.pm.

No, it couldn't find Date/Manip.pm

Also notice that your OS is CaSe SeNSitIVe.

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: Thu, 23 Nov 2006 02:40:09 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: FAQ 6.19 What good is "\G" in a regular expression?
Message-Id: <ek31rh.16o.1@news.isolution.nl>

Darren Dunham schreef:
> Dr.Ruud:

>> Where is the c-flag (or should it be called the c-modifier)
>> documented?
>
> perlop and perlreref both describe those flags.

Yes, I keep wondering why it isn't described in perlre. Also why it is
sometimes called "flag" or even "modifier flag", where "modifier" seems
to be the preferred name.

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Thu, 23 Nov 2006 02:11:00 GMT
From: boyd <tbmoore9@verizon.net>
Subject: Re: FAQ 6.19 What good is "\G" in a regular expression?
Message-Id: <tbmoore9-32478B.21102122112006@news.verizon.net>

In article <ek31rh.16o.1@news.isolution.nl>,
 "Dr.Ruud" <rvtol+news@isolution.nl> wrote:

> Darren Dunham schreef:
> > Dr.Ruud:
> 
> >> Where is the c-flag (or should it be called the c-modifier)
> >> documented?
> >
> > perlop and perlreref both describe those flags.
> 
> Yes, I keep wondering why it isn't described in perlre. Also why it is
> sometimes called "flag" or even "modifier flag", where "modifier" seems
> to be the preferred name.

From perldoc perlop:

   You can intermix "m//g" matches with "m/\G.../g", where "\G" is a 
zero-width assertion that matches the exact position where the previous 
"m//g", if any, left off.  Without the "/g" modifier, the "\G" assertion 
still anchors at pos(), but the match is of course only attempted once.  
Using "\G" without "/g" on a target string that has not previously had a 
"/g" match applied to it is the same as using the "\A" assertion to 
match the beginning of the string.  Note also that, currently, "\G" is
only properly supported when anchored at the very beginning of the 
pattern.   

Boyd


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

Date: Thu, 23 Nov 2006 02:34:09 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: FAQ 6.19 What good is "\G" in a regular expression?
Message-Id: <1udf34-t0i.ln1@osiris.mauzo.dyndns.org>


Quoth "Dr.Ruud" <rvtol+news@isolution.nl>:
> Darren Dunham schreef:
> > Dr.Ruud:
> 
> >> Where is the c-flag (or should it be called the c-modifier)
> >> documented?
> >
> > perlop and perlreref both describe those flags.
> 
> Yes, I keep wondering why it isn't described in perlre.

I guess the reason is that /imsx modify the pattern (which is why they
appear in stringified qr//), whereas /cgo modify the matching operation.
To put this another way, in a language like C a match like
    
    $x =~ /^abc/imgc;

would be expressed as something like

    char *x;
    regex *rx;

    rx = compile_regex("^abc", RX_CASELESS | RX_MULTILINE);
    regex_match(x, rx, RX_GLOBAL | RX_NORESET);

which is in fact more-or-less how pcre does it. Thus /imsx are part of
the 'pattern language' and belong in perlre, but /cgo are part of the
'match operator' and belong in perlop.

> Also why it is
> sometimes called "flag" or even "modifier flag", where "modifier" seems
> to be the preferred name.

Why not? TMTOWTnameI :)

Ben

-- 
You poor take courage, you rich take care:
The Earth was made a common treasury for everyone to share
All things in common, all people one.                [benmorrow@tiscali.co.uk]
'We come in peace'---the order came to cut them down.


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

Date: Wed, 22 Nov 2006 18:41:43 -0800
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 6.19 What good is "\G" in a regular expression?
Message-Id: <221120061841430249%brian.d.foy@gmail.com>

In article <ek1b8j.k0.1@news.isolution.nl>, Dr.Ruud
<rvtol+news@isolution.nl> wrote:

> PerlFAQ Server schreef:

> >     Suppose you want to match all of consective pairs of digits in a

> consecutive

> >     pos()) even if a match on the same string as failed in the

> has failed

I've fixed the spelling errors. Thanks,

> Where is the c-flag (or should it be called the c-modifier) documented?

I also added a reference to perlop and perlreref.

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Thu, 23 Nov 2006 02:46:00 GMT
From: boyd <tbmoore9@verizon.net>
Subject: Re: FAQ 7.15 How do I create a static variable?
Message-Id: <tbmoore9-B7B67F.21460022112006@news.verizon.net>

In article <m3cf34-6hv.ln1@blue.stonehenge.com>,
 PerlFAQ Server <brian@stonehenge.com> wrote:

> This is an excerpt from the latest version perlfaq7.pod, which
> comes with the standard Perl distribution. These postings aim to 
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is at http://faq.perl.org .
> 
> --------------------------------------------------------------------
> 
> 7.15: How do I create a static variable?
> 
>     (contributed by brian d foy)
> 
>     Perl doesn't have "static" variables, which can only be accessed from
>     the function in which they are declared. You can get the same effect
>     with lexical variables, though.
> 
>     You can fake a static variable by using a lexical variable which goes
>     out of scope. In this example, you define the subroutine "counter", and
>     it uses the lexical variable $count. Since you wrap this in a BEGIN
>     block, $count is defined at compile-time, but also goes out of scope at
>     the end of the BEGIN block. The BEGIN block also ensures that the
>     subroutine and the value it uses is defined at compile-time so the
>     subroutine is ready to use just like any other subroutine, and you can
>     put this code in the same place as other subroutines in the program text
>     (i.e. at the end of the code, typically). The subroutine "counter" still
>     has a reference to the data, and is the only way you can access the
>     value (and each time you do, you increment the value). The data in chunk
>     of memory defined by $count is private to "counter".
> 
>         BEGIN {
>             my $count = 1;
>             sub counter { $count++ }
>         }
> 
>         my $start = count();
> 
>         .... # code that calls count();
> 
>         my $end = count();
> 
>     In the previous example, you created a function-private variable because
>     only one function remembered its reference. You could define multiple
>     functions while the variable is in scope, and each function can share
>     the "private" variable. It's not really "static" because you can access
>     it outside the function while the lexical variable is in scope, and even
>     create references to it. In this example, "increment_count" and
>     "return_count" share the variable. One function adds to the value and
>     the other simply returns the value. They can both access $count, and
>     since it has gone out of scope, there is no other way to access it.
> 
>         BEGIN {
>             my $count = 1;
>             sub increment_count { $count++ }
>             sub return_count    { $count }
>         }
> 
>     To declare a file-private variable, you still use a lexical variable. A
>     file is also a scope, so a lexical variable defined in the file cannot
>     be seen from any other file.
> 
>     See "Persistent Private Variables" in perlsub for more information. The
>     discussion of closures in perlref may help you even though we did not
>     use anonymous subroutines in this answer. See "Persistent Private
>     Variables" in perlsub for details.
> 
> 
> 
> --------------------------------------------------------------------
> 
> The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
> are not necessarily experts in every domain where Perl might show up,
> so please include as much information as possible and relevant in any
> corrections. The perlfaq-workers also don't have access to every
> operating system or platform, so please include relevant details for
> corrections to examples that do not work on particular platforms.
> Working code is greatly appreciated.
> 
> If you'd like to help maintain the perlfaq, see the details in 
> perlfaq.pod.

oops - I think brian meant:

BEGIN{
    my $count = 1;
    sub counter { $count++ }
}

my $start = counter();  

in his first example.

Boyd


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

Date: 22 Nov 2006 22:37:27 -0800
From: "IJALAB" <balaji.draj@gmail.com>
Subject: File open problem
Message-Id: <1164263847.356801.32580@f16g2000cwb.googlegroups.com>



I am trying to take the files as command line arguments and do some
formatting to the files based on their extensions. I am getting error
in the file open when i use $ARGV[$i]
Also, I am assigning a fixed name to my files. can i dynamically do
them based on my input file names?

print $#ARGV;
$copypath = "<path>";
for ($i=0;$i<=$#ARGV;$i= $i + 1)
{

$b0 = system("copy $ARGV[$i] $copypath\\scripts");
$b1 = chdir ("$copypath\\scripts");
$extn = substr($ARGV[$i],-4,4);
print $extn, "\n";
print $ARGV[$i];
$file = $ARGV[$i];
if ($extn == ".txt")
{

#Error here!!!
open ($fh, '<$ARGV[$i]') or die "Cannot open Inputfile: ";
open ($ofh, '>OutFile.txt') or die "Cannot open Output File:";


while (my $line = <$fh>) {
<Formatting here>


}


close $fh;
close $ofh;
$b3 = chdir ("$copypath");

}

elsif ($extn == ".csv")
{
#Error here!!!
open my $f2h, '<', '$ARGV[$i]' or die "Cannot open InputFile.txt: ";
open my $of2h, '>', 'OutFile.csv' or die "Cannot open Output File:";


while (my $line = <$f2h>) {
<Formatting exp here>



}


close $f2h;
close $of2h;
$b3 = chdir ("$copypath");
}
}


thanks
bala



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

Date: Thu, 23 Nov 2006 00:52:51 -0600
From: "Dan Mercer" <damercer@comcast.net>
Subject: Re: File open problem
Message-Id: <tK6dnSe0Sfrb2PjYnZ2dnUVZ_oednZ2d@comcast.com>


"IJALAB" <balaji.draj@gmail.com> wrote in message news:1164263847.356801.32580@f16g2000cwb.googlegroups.com...
:
:
: I am trying to take the files as command line arguments and do some
: formatting to the files based on their extensions. I am getting error
: in the file open when i use $ARGV[$i]
: Also, I am assigning a fixed name to my files. can i dynamically do
: them based on my input file names?
:
: print $#ARGV;
: $copypath = "<path>";
: for ($i=0;$i<=$#ARGV;$i= $i + 1)
: {
:
: $b0 = system("copy $ARGV[$i] $copypath\\scripts");
: $b1 = chdir ("$copypath\\scripts");
: $extn = substr($ARGV[$i],-4,4);
: print $extn, "\n";
: print $ARGV[$i];
: $file = $ARGV[$i];
: if ($extn == ".txt")
: {
:
: #Error here!!!
: open ($fh, '<$ARGV[$i]') or die "Cannot open Inputfile: ";

no variable substitution inside single quotes

use strict;
use warnings;

Dan Mercer
: open ($ofh, '>OutFile.txt') or die "Cannot open Output File:";
:
:
: while (my $line = <$fh>) {
: <Formatting here>
:
:
: }
:
:
: close $fh;
: close $ofh;
: $b3 = chdir ("$copypath");
:
: }
:
: elsif ($extn == ".csv")
: {
: #Error here!!!
: open my $f2h, '<', '$ARGV[$i]' or die "Cannot open InputFile.txt: ";
: open my $of2h, '>', 'OutFile.csv' or die "Cannot open Output File:";
:
:
: while (my $line = <$f2h>) {
: <Formatting exp here>
:
:
:
: }
:
:
: close $f2h;
: close $of2h;
: $b3 = chdir ("$copypath");
: }
: }
:
:
: thanks
: bala
:




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

Date: Wed, 22 Nov 2006 22:50:44 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: File open problem
Message-Id: <4vsf34x1o9.ln2@goaway.wombat.san-francisco.ca.us>

On 2006-11-23, IJALAB <balaji.draj@gmail.com> wrote:
>
>
> I am trying to take the files as command line arguments and do some
> formatting to the files based on their extensions. I am getting error
> in the file open when i use $ARGV[$i]

See below.

> Also, I am assigning a fixed name to my files. can i dynamically do
> them based on my input file names?

Of course.  Parse the input file name for what you want, then
use that parsed name as the name of the output file.  Read perlreref
and/or perlretut for help in this area.

> print $#ARGV;

use strict;
use warnings;

> $copypath = "<path>";
> for ($i=0;$i<=$#ARGV;$i= $i + 1)

This is a yucky-looking idiom.  Better to use

for my $filename (@ARGV)

Then you can address each file as $filename in your for loop
instead of as $ARGV[$i].

> $b0 = system("copy $ARGV[$i] $copypath\\scripts");

File::Copy is preferable to spawning a subshell.

> $extn = substr($ARGV[$i],-4,4);

Are all your extensions four characters?  Mine aren't.

> #Error here!!!
> open ($fh, '<$ARGV[$i]') or die "Cannot open Inputfile: ";

If you read perldoc -f open, you'll notice a lot of references to
the special variable $!, which is the error message that a system
call returns.  If you include it, then you will see exactly why
your open is failing.

--keith

-- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information



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

Date: Wed, 22 Nov 2006 21:43:10 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: generic increment of number/string
Message-Id: <esse34-v0c.ln1@osiris.mauzo.dyndns.org>


Quoth "Paul Lalli" <mritty@gmail.com>:
> alexxx.magni@gmail.com wrote:
> > What I had problem with, was that at first I checked on the command line,
> > and there I discovered what still puzzles me:
> >
> > 1) output of your program in a script:
> > 0001
> > 0002
> > 0003
> > ...
> >
> > 2) while instead, perl -e 'for my $num ('0001' .. '0100') {print
> > "$num\n";}'   gives:
> > 1
> > 2
> > 3
> > ...
> 
> Did you actually look at the *entire* list, not just the first three?
> It only goes up to 64, not 100.  That's because you're using single
> quotes within the program, and as delimeters to the perl -e.
> Therefore, Perl is not seeing single quoted strings.  Instead, Perl is
> seeing the shell's interpretation of 0001 and 0100, which are octal 1
> and octal 64, respectively.

Minor nit: this has nothing to do with the shell. 0100 is not special to
the shell. The important thing is that perl sees

    for my $num (0001 .. 0100) {

instead of

    for my $num ('0001' .. '0100') {

, and *perl* interprets 0100 as '100 octal' = 64.

> Change the inner single quotes to double quotes, and everything will
> work out...

Or escape the quotes, or use q//. That's why it's there, after all.

Ben

-- 
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces mollit animos, tristesque mentes erigit.|benmorrow@tiscali.co.uk
Musica vel ipsas arbores et horridas movet feras.     |


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

Date: Wed, 22 Nov 2006 21:17:43 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: How to change Perl's concept of a newline in regexps?
Message-Id: <ncre34-biv.ln1@osiris.mauzo.dyndns.org>


Quoth "Dr.Ruud" <rvtol+news@isolution.nl>:
>
> Maybe there exists a :cr layer for Mac-type text files?

PerlIO::eol, which is IMHO greatly superior to :crlf in all
circumstances.

Ben

-- 
Many users now operate their own computers day in and day out on various
applications without ever writing a program. Indeed, many of these users
cannot write new programs for their machines...
    -- F.P. Brooks, 'No Silver Bullet', 1987      [benmorrow@tiscali.co.uk]


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

Date: 22 Nov 2006 17:26:29 -0800
From: "Stevie" <steviehaston@hotmail.com>
Subject: Is a file in use?
Message-Id: <1164245189.220580.115840@e3g2000cwe.googlegroups.com>

Very simply I'm sure, but how does one check whether a file is 'in use'
using perl?
Thanks a million
Stevie



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

Date: 23 Nov 2006 01:35:52 GMT
From: xhoster@gmail.com
Subject: Re: Is a file in use?
Message-Id: <20061122203620.579$FP@newsreader.com>

"Stevie" <steviehaston@hotmail.com> wrote:
> Very simply I'm sure, but how does one check whether a file is 'in use'
> using perl?

Not all simple.  It depends very much on the OS and/or the file system you
use.  Usually you lock the file, but that generally depends on all other
people who put the file "in use" also using locks.  You maybe could also
use OS-dependent tools, like lsof on Linux, to see who has the file open.

Xho

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


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

Date: Wed, 22 Nov 2006 19:55:06 -0800
From: Michael Vilain <vilain@spamcop.net>
Subject: Re: Is a file in use?
Message-Id: <vilain-D6A36C.19550622112006@comcast.dca.giganews.com>

In article <1164245189.220580.115840@e3g2000cwe.googlegroups.com>,
 "Stevie" <steviehaston@hotmail.com> wrote:

> Very simply I'm sure, but how does one check whether a file is 'in use'
> using perl?
> Thanks a million
> Stevie

That's not a portable OS feature.  Unless you explicitly lock a file and 
have a facility to check for locking, you're stuck with how each OS 
checks this feature.  Linux and MacOS X will gladly open a file R/O even 
though another process has it open and is writing to it.  Someone 
suggested using lsof on Unix systems, which is _very_ non-portable and 
not all systems install lsof "out of the box".

Do you have a specific instance you want to code for?  What happens with 
the file is busy?  Does the open() or the read fail?

-- 
DeeDee, don't press that button!  DeeDee!  NO!  Dee...





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

Date: Thu, 23 Nov 2006 05:42:11 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Nov 23 2006
Message-Id: <J9656B.A7I@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

AI-FANN-0.07
http://search.cpan.org/~salva/AI-FANN-0.07/
Perl wrapper for the Fast Artificial Neural Network library
----
Astro-0.69
http://search.cpan.org/~cphil/Astro-0.69/
----
B-LintSubs-0.01
http://search.cpan.org/~pevans/B-LintSubs-0.01/
----
Bot-BasicBot-Pluggable-Module-CoreList-0.03
http://search.cpan.org/~book/Bot-BasicBot-Pluggable-Module-CoreList-0.03/
IRC frontend to Module::CoreList
----
CGI-FormBuilder-Template-HTC-0.01
http://search.cpan.org/~tinita/CGI-FormBuilder-Template-HTC-0.01/
----
CGI-Session-Submitted-1.04
http://search.cpan.org/~leocharre/CGI-Session-Submitted-1.04/
Automatic session and persistence of query data.
----
CGI-Session-Submitted-1.05
http://search.cpan.org/~leocharre/CGI-Session-Submitted-1.05/
Automatic session and persistence of query data.
----
Catalyst-Plugin-Authentication-Credential-Hatena-0.03
http://search.cpan.org/~typester/Catalyst-Plugin-Authentication-Credential-Hatena-0.03/
Hatena authentication for Catalyst
----
Catalyst-Plugin-Hooks-0.03
http://search.cpan.org/~berikv/Catalyst-Plugin-Hooks-0.03/
Add hooks to Catalyst engine actions
----
DateTime-Format-Natural-EN-0.10
http://search.cpan.org/~schubiger/DateTime-Format-Natural-EN-0.10/
Create machine readable date/time with natural parsing logic
----
Finance-MICR-LineParser-1.06
http://search.cpan.org/~leocharre/Finance-MICR-LineParser-1.06/
validate and parse a MICR code from a string
----
Geo-Coder-Ja-0.02
http://search.cpan.org/~jiro/Geo-Coder-Ja-0.02/
geocoder.ja library module for Perl
----
Hash-Extract-0.01
http://search.cpan.org/~hio/Hash-Extract-0.01/
extract hash values onto lexical variables. 1
----
Jemplate-0.20
http://search.cpan.org/~ingy/Jemplate-0.20/
JavaScript Templating with Template Toolkit
----
Konstrukt-0.5-beta7
http://search.cpan.org/~twittek/Konstrukt-0.5-beta7/
Web application/design framework
----
Net-Packet-Shell-0.20
http://search.cpan.org/~gomor/Net-Packet-Shell-0.20/
Scapy like implementation using Net::Packet, just to prove it
----
Net-SSL-ExpireDate-1.01
http://search.cpan.org/~hirose/Net-SSL-ExpireDate-1.01/
obtain expiration date of certificate
----
Objects-Collection-0.27
http://search.cpan.org/~zag/Objects-Collection-0.27/
abstract class for collections of data.
----
Objects-Collection-0.28
http://search.cpan.org/~zag/Objects-Collection-0.28/
abstract class for collections of data.
----
POE-Component-CPAN-YACSmoke-0.05
http://search.cpan.org/~bingos/POE-Component-CPAN-YACSmoke-0.05/
bringing the power of POE to CPAN smoke testing.
----
Regexp-Ethiopic-0.15
http://search.cpan.org/~dyacob/Regexp-Ethiopic-0.15/
Regular Expressions Support for Ethiopic Script.
----
Rose-DB-0.731
http://search.cpan.org/~jsiracusa/Rose-DB-0.731/
A DBI wrapper and abstraction layer.
----
Rose-DB-Object-0.757
http://search.cpan.org/~jsiracusa/Rose-DB-Object-0.757/
Extensible, high performance RDBMS-OO mapper.
----
Rose-HTML-Objects-0.543
http://search.cpan.org/~jsiracusa/Rose-HTML-Objects-0.543/
Object-oriented interfaces for HTML.
----
String-Equivalence-Amharic-0.04
http://search.cpan.org/~dyacob/String-Equivalence-Amharic-0.04/
Normalization Utilities for Amharic.
----
Switch-2.11
http://search.cpan.org/~rgarcia/Switch-2.11/
A switch statement for Perl
----
Text-Sprintf-Named-0.01
http://search.cpan.org/~shlomif/Text-Sprintf-Named-0.01/
sprintf-like function with named conversions
----
Text-TransMetaphone-0.07
http://search.cpan.org/~dyacob/Text-TransMetaphone-0.07/
Translingual phonetic encoding of words.
----
Tie-RefHash-1.35_01
http://search.cpan.org/~nuffin/Tie-RefHash-1.35_01/
use references as hash keys
----
XML-XPathScript-1.46_02
http://search.cpan.org/~yanick/XML-XPathScript-1.46_02/
a Perl framework for XML stylesheets
----
ack-1.32
http://search.cpan.org/~petdance/ack-1.32/
grep-like text finder for large trees of text
----
bioperl-1.5.2_004-RCf
http://search.cpan.org/~sendu/bioperl-1.5.2_004-RCf/
----
bioperl-1.5.2_004-RCg
http://search.cpan.org/~sendu/bioperl-1.5.2_004-RCg/
----
classes-0.943
http://search.cpan.org/~rmuhle/classes-0.943/
conventional Perl 5 classes


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Wed, 22 Nov 2006 23:50:44 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Regex exactly 0, 1 or 2 matches, {0,2} not working
Message-Id: <kb4f34-2u7.ln1@osiris.mauzo.dyndns.org>


Quoth "GGB667" <ggb667@gmail.com>:
> I was really hoping to keep it as a pure regular expression.  What I've
> ended up doing was having a boatload of different expressions, EX: one
> with a comma, 1 with a comma and a space, one with a comma, space and
> number 1-9, and one with a comma, space, number 1-9 and 0-5 and one
> with all that and a-f after it.  I also have one with - or --.  It's
> ugly.  Now here's the kicker.  The numbers are not allowed to be
> identical!

You haven't quoted enough context for me to see what your original
problem was (and the beginning of this thread is no longer in my spool),
but...

> So 1a, 2b is OK, but 1a, 1f is not!
> 
> I have absolutely no idea how to implement that unless I use a program.
> 
> So basically how can you make a regular expression with 2 DIFFERENT
> numbers?
> 
> I thought there was some backreference thing you could use, but I can't
> seem to get it to work.
> 
> So say 1,5 or 1,3 or 1,7 but not 2,2 or 1,1.

 ...something like /^ (\d+) , (?! \1 $) \d+ $/x will match sequences like
that. If you don't want the regex anchored you will have to find some
other way to locate the end of a number (or whatever your pattern
actually is); otherwise things like 1,11 will fail. This may of course
be what you want, in which case you need to remove the $ from inside the
(?!).

Ben

-- 
"If a book is worth reading when you are six,         * benmorrow@tiscali.co.uk
it is worth reading when you are sixty."  [C.S.Lewis]


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

Date: Thu, 23 Nov 2006 06:34:38 GMT
From: Alan_C <mtbr0228AT@sbcglobalDOT.net>
Subject: Re: Stuff a hash from two source files
Message-Id: <87hcwq8xx5.fsf@AB60R.localdomain>

"DJ Stunks" <DJStunks@gmail.com> writes:
> banker123 wrote:
> >
> > #!/usr/bin/perl
<snip>
> okay, now we're getting somewhere.  code that compiles.
<snip>
> something like this:  (untested)
<snip>
>     ($box,$group) = split;
>     $data{$box}{group} = $group;

al@AB60R:~$ tst_hash
712482 firstblue 1
712481 firstblack 2
712480 firstgreen 3

I see that this removes dupes, appends each single digit to each appropriate
line, sorted by the single digits.  Do I have that right? (my output is above,
there)

I understand the part that I did in the below code.  But I do not understand
each code line below that I've appended an #?? onto.

I seek any sort of help that would in turn help me to understand these lines
that I do not grasp (explanations, terminologies of what for me to study,
perldocs, etc.)  Thanks.


#!/usr/bin/perl 
use strict;
use warnings;
use diagnostics;

# open ('INFO', 'C:/sort.txt') or die "Cannot open file: $!";
# open ('BOX', 'C:/box.txt') or die "Cannot open file: $!";

############ important notice #################
# where <INFO> be/is the first 3 lines of DATA
# and <BOX> be/is the last 3 lines of DATA
my %data;
my @box_items; # gather_for_BOX
my ($box, $prior, $group);
# while (<INFO>) {
my $i = 0; # gather_for_BOX
while (<DATA>) {
########## gather_for_BOX ############
   $i++;
   if ($i > 3) {
      push @box_items, $_;
      next;
   }
########### end of gather_for_BOX ###########
   ($box, $prior) = split;
   $data{$box}{prior} = $prior; #??
}
# print @box_items;

# while (<BOX>) {
foreach ( @box_items ) {
   ($box,$group) = split;
   $data{$box}{group} = $group; #??
}

for my $table ( sort by_type( keys %data )) {
   my @data = ($table, @{ $data{$table} } {qw/group prior/}); #??
   print "@data\n";
}

sub by_type {
     $data{$a}{prior} <=> $data{$b}{prior}; #??
}
__DATA__
712480 3
712481 2
712482 1
712480 firstgreen
712481 firstblack
712482 firstblue

-- 
Alan.


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

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 V10 Issue 9999
***************************************


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