[28145] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9509 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 21 18:06:08 2006

Date: Fri, 21 Jul 2006 15:05:07 -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           Fri, 21 Jul 2006     Volume: 10 Number: 9509

Today's topics:
    Re: Can anybody help me get a job or work  robic0
    Re: Can anybody help me get a job or work  <tadmc@augustmail.com>
    Re: Can anybody help me get a job or work <uri@stemsystems.com>
    Re: Clock <fgchan@gmail.com>
    Re: Clock <benmorrow@tiscali.co.uk>
    Re: How to find out if a certain value is in a list? <tadmc@augustmail.com>
        Idiot Q: How to find index number of HASH match? <franzl.wisseworst@mailinator.net>
    Re: Need compress-zlib example for textfile into .gz <marc.bau@gmx.net>
    Re: Need Help with Program in Perl on a Netware Server <mumia.w.18.spam+nospam.usenet@earthlink.net>
    Re: Need Help with Program in Perl on a Netware Server <mritty@gmail.com>
    Re: Need Help with Program in Perl on a Netware Server <mumia.w.18.spam+nospam.usenet@earthlink.net>
    Re: Net:TFTPd questions - Want to upload configs via TF <tzz@lifelogs.com>
    Re: numeric sort on string like a123-3 <filippo2991@virgilio.it>
    Re: numeric sort on string like a123-3 <noreply@gunnar.cc>
    Re: numeric sort on string like a123-3 <tadmc@augustmail.com>
        On Computing and Its People <xah@xahlee.org>
        perl + regex bug? nitroamos@gmail.com
    Re: perl + regex bug? <mritty@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 21 Jul 2006 10:24:33 -0700
From: robic0
Subject: Re: Can anybody help me get a job or work 
Message-Id: <nb32c2t3810c84jo4u03qaqvq9mbfsq0tm@4ax.com>

On Thu, 20 Jul 2006 22:42:59 -0700, robic0 wrote:

>I'm almost on skid row now. I have a gun and I'm thinking  of ending it all.
>My family is almost starving and I have no prospects for work.
>
>Please help!
>robic0

A joke. This is all balogny, none of this is true.
robic0


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

Date: Fri, 21 Jul 2006 13:17:41 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Can anybody help me get a job or work 
Message-Id: <slrnec26i5.1kg.tadmc@magna.augustmail.com>

robic0 <> wrote:

> Subject: Can anybody help me get a job or work 


   http://www.mcdonalds.com/usa/work.html


HTH.


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


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

Date: Fri, 21 Jul 2006 14:01:31 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Can anybody help me get a job or work
Message-Id: <x7y7umltvo.fsf@mail.sysarch.com>

>>>>> "r" == robic0  <robic0> writes:

  r> On Thu, 20 Jul 2006 22:42:59 -0700, robic0 wrote:
  >> I'm almost on skid row now. I have a gun and I'm thinking  of ending it all.
  >> My family is almost starving and I have no prospects for work.
  >> 
  >> Please help!
  >> robic0

  r> A joke. This is all balogny, none of this is true.

damn, i was looking forward to your last moments here.

<not a joke>

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 21 Jul 2006 10:53:15 -0700
From: "TheOrangeRemix" <fgchan@gmail.com>
Subject: Re: Clock
Message-Id: <1153504395.203110.325530@s13g2000cwa.googlegroups.com>

Thank you all for the suggestions. What I am looking for is a Windows
API that displays a editable clock and whatever the user inputs will be
read into the script and processed in an array.
Is there a function or a set of functions that I can use to accomplish
these two tasks?



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

Date: Fri, 21 Jul 2006 20:19:37 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Clock
Message-Id: <9vl7p3-8mg.ln1@osiris.mauzo.dyndns.org>


Quoth "TheOrangeRemix" <fgchan@gmail.com>:
> Thank you all for the suggestions. What I am looking for is a Windows
> API that displays a editable clock and whatever the user inputs will be
> read into the script and processed in an array.

AFAIK windows doesn't provide such a control. You could build one
yourself, using one of the toolkits I mentioned; or you could see if you
can find an ActiveX control that does what you want (though this may be
a lot of pain :) ).

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                         benmorrow@tiscali.co.uk


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

Date: Fri, 21 Jul 2006 10:37:16 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to find out if a certain value is in a list?
Message-Id: <slrnec1t5c.m9e.tadmc@magna.augustmail.com>


[ TOFU repaired ]


TN <tjpn@not_spam.surfeu.fi> wrote:
> "Tad McClellan" <tadmc@augustmail.com> kirjoitti 
> viestissä:slrnebure8.drq.tadmc@magna.augustmail.com...
>> TN <tjpn@not_spam.surfeu.fi> wrote:
>>
>>> what would be the shortest (or best...) way to find out if a certain 
>>> value
>>> is in the list like in the code here:
>>            ^^^^
>>            ^^^^
>>
>>   perldoc -q list
>>
>>       How can I tell whether a certain element is contained in a list or
>>       array?


> Great,
> that gave me a good solution.


Exactly so.

That is why good netiquette demands checking the FAQ before posting.


> Thanks,


You're welcome.

Please see the Posting Guidelines that are posted here frequently.


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


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

Date: Fri, 21 Jul 2006 19:58:46 +0200
From: Franzl Wisseworst <franzl.wisseworst@mailinator.net>
Subject: Idiot Q: How to find index number of HASH match?
Message-Id: <e9r5gj$gtk$03$1@news.t-online.com>

I wonder how to find the reference to the HASH position based on a matching 
'page-name'. My page-name is always known in the $current::page

$current::page;

Here are two hash tables, with 3 links each:

%location_en = ('page1.html' => 'page one',
                          'bla.html' => 'blabla',
                          'something.html' => 'Something');

%location_de = ('seite1.html' => 'Seite eins',
                          'blau.html' => 'Blau',
                          'ding.html' => 'Ding');

The script also knows the user is on the 'en' domain in order to search for 
a match in %location_en, so knowing this, how could it crawl through the 
%location_en hash to return the index number of that array in order to 
generate a link to the same position in %location_de, i.e. blau.html?

No doub't many ways exist, while in this case the simplest would be the 
best, and without performance limitations (eg. use of RE's). Its simply an 
html pre-processing procedure that runs once in a blue moon on a localhost 
to generate static pages that are later sent up on a server in plain html.



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

Date: Fri, 21 Jul 2006 17:06:20 +0200
From: "Marc Bauer" <marc.bau@gmx.net>
Subject: Re: Need compress-zlib example for textfile into .gz
Message-Id: <44c0ed71$0$31168$bb690d87@news.main-rheiner.de>

hi

yes, i corrected this. but the CRC errors are *not* gone.


Regards
Marc 




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

Date: Fri, 21 Jul 2006 15:33:03 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: Need Help with Program in Perl on a Netware Server
Message-Id: <Ps6wg.2789$157.2400@newsread3.news.pas.earthlink.net>

On 07/21/2006 08:57 AM, fhadzocos@gmail.com wrote:
> I have a huge folder with 44 thousand files I need to keep only the
> last file for each type in that folder
> 
> ex
> 
> workstation1.001
> workstation1.002
> workstation2.49
> workstation2.56
> workstation20.560
> workstation20.561
> workstation20.562
> 
> In that example I need to keep workstation1.002 workstation2.56
> workstation20.562 and this would continue until the end of the files.
> There is only one folder to look in.
> I have no idea how to go about doing this in perl. I'm very new to perl
> and do not wish to make an inefficient program.
> 
> Thanks
> Mobius1982
> 

I would create a hash for the filenames (without extensions). 
For each file found, I'd put the base name in the hash as a 
key, and the full file name would go in if either there were 
no value for that hash key or if the new filename-extension 
were numerically larger than the hash value's 
filename-extension. This creates a list of files to keep (as 
hash values).

Then I would make those files (the hash values) read-only and 
delete every other file in the folder. Afterward, I'd remove 
the read-only flags from the remaining files.


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

Date: 21 Jul 2006 08:46:23 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Need Help with Program in Perl on a Netware Server
Message-Id: <1153496783.519692.321480@s13g2000cwa.googlegroups.com>

Mumia W. wrote:

> Then I would make those files (the hash values) read-only and
> delete every other file in the folder. Afterward, I'd remove
> the read-only flags from the remaining files.

Why the read-only bit of this?  What does that gain for you?

Paul Lalli



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

Date: Fri, 21 Jul 2006 19:03:29 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: Need Help with Program in Perl on a Netware Server
Message-Id: <5y9wg.7826$vO.1053@newsread4.news.pas.earthlink.net>

On 07/21/2006 10:46 AM, Paul Lalli wrote:
> Mumia W. wrote:
> 
>> Then I would make those files (the hash values) read-only and
>> delete every other file in the folder. Afterward, I'd remove
>> the read-only flags from the remaining files.
> 
> Why the read-only bit of this?  What does that gain for you?
> 
> Paul Lalli
> 

Come to think about it, not much.

My algorithm only identifies files to keep--not files to
delete. For deleting files, I planned on using 'rm *', and
that means that the files to keep would have to be read-only.

But now that I think about it, 'rm *' won't like a parameter
list that's 44 thousand items big, so I'd have to use 
opendir/closedir and unlink. And since that's the case, I 
might as well check each file against the hash to test if it 
should be deleted.

Oh well, TMTOWTDI.





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

Date: Fri, 21 Jul 2006 16:18:31 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Net:TFTPd questions - Want to upload configs via TFTP
Message-Id: <g69lkqmhfu0.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 20 Jul 2006, nospam@example.com wrote:

> I am writing a script that will log into my network equipment and backup
> the configurations to a TFTP server.  Since I don't want the security
> risk of a TFTP server running all the time, I want to create a TFTP
> server when the script starts and destroy it when I am done.  My problem
> is that the Net::TFTPd module does not seem to process any of the
> requests.  Issuing a "netstat -a" does show a socket created on port 69,
> but nothing else.  The script times out and dies.  Is that module
> compatible with current versions of perl, since it was written for perl
> 5.006?
>
> Has anyone else done this or had experience trying to do this?  I am
> running perl under RedHat Enterprise Linux 4.  Suggestions or actual
> code would be helpful and appreciated.

If you post the shortest version of your code that shows the problem,
I'm sure you'll get a lot more help.  As it is, no one can magically
answer your question since we don't know what you're doing in your code.

Ted


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

Date: 21 Jul 2006 11:18:37 -0700
From: "filippo" <filippo2991@virgilio.it>
Subject: Re: numeric sort on string like a123-3
Message-Id: <1153505917.761280.137580@s13g2000cwa.googlegroups.com>

Paul Lalli ha scritto:
> (Note that both of these will leave a12-1, c12, and c12-1 in a random
> order in Perl 5.6 and lower, and in the same order as they were in the
> original list in Perl 5.8 and higher.  Altering the sort to take the
> second number and/or the beginning letter into account is left as an
> excercise to the OP. :-) )

Hi Paul, thanks for the opportunity to develope my brain but I confess
that I could not succeed :-)
I'd like to have them sorted on the minor numeric, es

a12
a12-1
a12-2
a12-3
a13

could you give me at least a hint?
Thanks

Filippo



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

Date: Fri, 21 Jul 2006 20:34:00 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: numeric sort on string like a123-3
Message-Id: <4icku4F37vjgU1@individual.net>

filippo wrote:
>>(Note that both of these will leave a12-1, c12, and c12-1 in a random
>>order in Perl 5.6 and lower, and in the same order as they were in the
>>original list in Perl 5.8 and higher.  Altering the sort to take the
>>second number and/or the beginning letter into account is left as an
>>excercise to the OP. :-) )
> 
> Hi Paul, thanks for the opportunity to develope my brain but I confess
> that I could not succeed :-)

BS. Use the docs (perldoc -f sort) and make an attempt.

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


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

Date: Fri, 21 Jul 2006 15:00:11 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: numeric sort on string like a123-3
Message-Id: <slrnec2cib.28j.tadmc@magna.augustmail.com>

filippo <filippo2991@virgilio.it> wrote:
> Paul Lalli ha scritto:
>> (Note that both of these will leave a12-1, c12, and c12-1 in a random
>> order in Perl 5.6 and lower, and in the same order as they were in the
>> original list in Perl 5.8 and higher.  Altering the sort to take the
>> second number and/or the beginning letter into account is left as an
>> excercise to the OP. :-) )
> 
> Hi Paul, thanks for the opportunity to develope my brain but I confess
> that I could not succeed :-)
> I'd like to have them sorted on the minor numeric, es
> 
> a12
> a12-1
> a12-2
> a12-3
> a13
> 
> could you give me at least a hint?


my @sorted = map { $_->[0] }
sort { $a->[1] cmp $b->[1] or
       $a->[2] <=> $b->[2] or
       $a->[3] <=> $b->[3]
     }
map { [$_, /^([a-z])(\d+)-?(\d*)/ ] } @strings;


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


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

Date: 21 Jul 2006 12:16:45 -0700
From: "Xah Lee" <xah@xahlee.org>
Subject: On Computing and Its People
Message-Id: <1153509405.284210.48400@m79g2000cwm.googlegroups.com>

Hi all,

in the past years, i have written few hundreds of essays and tutorials
on computing. Now, i've but a index page to this collection:
http://xahlee.org/Periodic_dosage_dir/skami_prosa.html

many of these, originated from online forum. The writing style is
enticing and the content astute.

also, as many of you may know, in the past month there's some
controversy regarding me, that resulted in a small web hosting company
kicking me out, giving the legal reason of _no reason_ as by the
contract agreement (with a 30 days notice in advance). I feel there's
some public obligation to give this update. More details is at
http://xahlee.org/Periodic_dosage_dir/t2/harassment.html

i have been busy in the past month so i haven't wrote anything new
(regarding computing). Recently i started to do Java again, and will
probably soon complete the other sections of this exposition:
What are OOP's Jargons and Complexities
http://xahlee.org/Periodic_dosage_dir/t2/oop.html

   Xah
   xah@xahlee.org
 =E2=88=91 http://xahlee.org/



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

Date: 21 Jul 2006 13:30:35 -0700
From: nitroamos@gmail.com
Subject: perl + regex bug?
Message-Id: <1153513835.324982.209140@i42g2000cwa.googlegroups.com>

hello -- i've been spending quite a bit of time trying to figure out
this issue, and now that i've found a workaround, i'm wondering if the
problem was a bug. basically, i have some code that looks like this:

$orbitals[$i] =~ /\s+(\d)\s+Orbital Energy/;
$index = $1;
$index--; $index++;

if($element =~ /_${index}_/ or $element =~ m/_$index$/){
      print "$element matches $& with index = $index\n";


}

this is just a small part of my program, so i hope i've shown enough to
isolate the bug. Basically, I'm trying to grab an integer out of a
string, and then look in another string to see if i have a match. i've
pasted what the output looks like at the bottom. as you can see, the
incorrect results are producing a subset of the matches I expect --
only the first pattern on the if line is matching.

for some reason, without the $index--; $index++; business, my second
pattern is not matching. after fooling around, it seems that somehow
it's entirely related to the $ anchor. although not what I want, if I
add a ^ anchor i can get matches with or without the $ anchor. so
somehow the $ anchor all by itself is not working unless i do the --/++
business.

what kind of weirdness is this? i've pasted perl -V at the bottom. if
this is some version specific bug, then that's all i need to know; i'm
ok with the workaround. but if there's something that i'm not
understanding, then i want to know what i'm missing.

thanks!



results where everything is working as expected (correctly):
_1 matches _1 with index = 1
_2 matches _2 with index = 2
_3 matches _3 with index = 3
_4 matches _4 with index = 4
_5 matches _5 with index = 5
_1_2 matches _1_ with index = 1
_1_2 matches _2 with index = 2
_1_3 matches _1_ with index = 1
_1_3 matches _3 with index = 3
_2_3 matches _2_ with index = 2
_2_3 matches _3 with index = 3
_1_4 matches _1_ with index = 1
_1_4 matches _4 with index = 4
_2_4 matches _2_ with index = 2
_2_4 matches _4 with index = 4
_3_4 matches _3_ with index = 3
_3_4 matches _4 with index = 4
_1_5 matches _1_ with index = 1
_1_5 matches _5 with index = 5
_2_5 matches _2_ with index = 2
_2_5 matches _5 with index = 5
_3_5 matches _3_ with index = 3
_3_5 matches _5 with index = 5
_4_5 matches _4_ with index = 4
_4_5 matches _5 with index = 5

results where the "$index--; $index++;" line has been commented out
(incorrect results):
_1_2 matches _1_ with index = 1
_1_3 matches _1_ with index = 1
_2_3 matches _2_ with index = 2
_1_4 matches _1_ with index = 1
_2_4 matches _2_ with index = 2
_3_4 matches _3_ with index = 3
_1_5 matches _1_ with index = 1
_2_5 matches _2_ with index = 2
_3_5 matches _3_ with index = 3
_4_5 matches _4_ with index = 4


here is what perl -V says:
Summary of my perl5 (revision 5.0 version 8 subversion 0)
configuration:
  Platform:
    osname=linux, osvers=2.4.21-1.1931.2.382.entsmp,
archname=i386-linux-thread-multi
    uname='linux str'
    config_args='-des -Doptimize=-O2 -g -pipe -march=i386 -mcpu=i686
-Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red
Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux
-Dvendorprefix=/usr -Dsiteprefix=/usr
-Dotherlibdirs=/usr/lib/perl5/5.8.0 -Duseshrplib -Dusethreads
-Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db
-Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio
-Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less
-isr'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef'
 useithreads=define usemultiplicity=
    useperlio= d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=un uselongdouble=
    usemymalloc=, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-DDEBUGGING -fno-strict-aliasing -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-DDEBUGGING -fno-strict-aliasing -I/usr/local/include
-I/usr/include/gdbm'
    ccversion='', gccversion='3.2.2 20030222 (Red Hat Linux 3.2.2-5)',
gccosandvers=''
gccversion='3.2.2 200302'
    intsize=r, longsize=r, ptrsize=5, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long'
k', ivsize=4'
ivtype='l, nvtype='double'
o_nonbl', nvsize=, Off_t='', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc'
l', ldflags =' -L/u'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
    perllibs=
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libper
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so', d_dlsymun=undef,
ccdlflags='-rdynamic
-Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE'
    cccdlflags='-fPIC'
ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5', lddlflags='s
Unicode/Normalize XS/A'


Characteristics of this binary (from libperl):
  Compile-time options: DEBUGGING MULTIPLICITY USE_ITHREADS
USE_LARGE_FILES PERL_IMPLICIT_CONTEXT
  Locally applied patches:
        MAINT18379
  Built under linux
  Compiled at Aug 13 2003 11:47:58
  @INC:
    /usr/lib/perl5/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.0
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/5.8.0
    .



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

Date: 21 Jul 2006 14:00:42 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: perl + regex bug?
Message-Id: <1153515642.449124.251470@p79g2000cwp.googlegroups.com>

nitroamos@gmail.com wrote:
> hello -- i've been spending quite a bit of time trying to figure out
> this issue, and now that i've found a workaround, i'm wondering if the
> problem was a bug.

So there's two possibilities:  You did something wrong, or Perl has a
bug that has never been detected or repaired.  It is exceedingly
arrogant to guess that the latter has a greater chance than the former,
IMHO.

> basically, i have some code that looks like this:

Please reduce your *real* code to the smallest possible script that
demonstrates the error, and yet is still a complete script we can run.

>
> $orbitals[$i] =~ /\s+(\d)\s+Orbital Energy/;

And what is the value of $i?  What are the values in @orbitals?

> $index = $1;

NEVER use $1, $2, $3 etc without first assuring that the pattern match
succeeded.  If the above pattern did not match, $1 will be whatever it
was after the last successful pattern match.  If either there was no
prior successful match, or that match did not contain any capturing
parentheses, $1 will be undef.

> $index--; $index++;

This is a sure sign that you're doing something wrong, but don't
understand what, so you're throwing random code at it until it almost
works.  Find and fix the *real* problem.

>
> if($element =~ /_${index}_/ or $element =~ m/_$index$/){

And now what is in $element?  How can you expect us to interpret your
results without telling us what these three critical pieces of
information are?

>       print "$element matches $& with index = $index\n";
>
>
> }
>
> this is just a small part of my program, so i hope i've shown enough to
> isolate the bug.

Again the assumption that Perl must be wrong instead of you.  And no,
there isn't enough code above for us to see what you've done wrong.

> Basically, I'm trying to grab an integer out of a
> string,

No, you're trying to grab a single digit out of a string.  Integers
include numbers such as "100", "42", and "8749312".  Yours will grab
only 0 through 9.  Perhaps that's your mistake?  We can't possibly know
without seeing the original strings you were trying to match.

> and then look in another string to see if i have a match. i've
> pasted what the output looks like at the bottom. as you can see, the
> incorrect results are producing a subset of the matches I expect --
> only the first pattern on the if line is matching.
>
> for some reason, without the $index--; $index++; business, my second
> pattern is not matching.

Here's my guess - about half the time, your pattern doesn't match
because you have an integer greater than 9 in your string.  Thus,
$index becomes undefined when you assign it to $1.  You're not using
warnings, so Perl doesn't bother telling you that you've included an
undef inside your pattern match, and instead treats it as the empty
string.  When you do the $index--; $index++; idiocy, Perl is forced to
treat the undef as the integer 0 instead.

As I said, this is a complete guess.  Without seeing your actual data,
there is no way of *knowing* what is happening.

> after fooling around, it seems that somehow
> it's entirely related to the $ anchor. although not what I want, if I
> add a ^ anchor i can get matches with or without the $ anchor. so
> somehow the $ anchor all by itself is not working unless i do the --/++
> business.

I find that remarkably unlikely, and am far more willing to bet you
have a bug in your diagnostic process.

> what kind of weirdness is this?

The weirdness that happens when you don't program with warnings, don't
check the return values of your pattern matches, and don't show
complete data when asking for help.

> i've pasted perl -V at the bottom. if
> this is some version specific bug, then that's all i need to know; i'm
> ok with the workaround. but if there's something that i'm not
> understanding, then i want to know what i'm missing.

We can't tell you that, because you haven't given enough information.

Please read the Posting Guidelines for this group.  They will give you
all sorts of hints on how to best ask questions in this and other
technical forums.

Paul Lalli



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

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


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