[22339] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4560 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 12 21:05:50 2003

Date: Wed, 12 Feb 2003 18: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           Wed, 12 Feb 2003     Volume: 10 Number: 4560

Today's topics:
    Re: $q->a( -href ... ) question (Ran)
        Accessing a remote DB (Robert F.)
    Re: Accessing a remote DB <eric.schwartz@hp.com>
        binary data and utf8 (I think) <spamtrap@lapsley.ukshells.co.uk>
    Re: binary data and utf8 (I think) <goldbb2@earthlink.net>
    Re: HELP! - error message not making sense <steven.smolinski@sympatico.ca>
    Re: High-speed directory listings (Seth Brundle)
    Re: Perl script to create new user in Linux. (Bill Werle)
    Re: Perl+Tk+MySQL for Win32 that *works*? (Jim Seymour)
    Re: Please explain this weird error message <flavell@mail.cern.ch>
    Re: Please explain this weird error message <elf@ee.ryerson.ca>
    Re: PREFIX and LIB args for Makefile (Sisyphus)
        Question about News::NNTPClient Module <extendedpartition@NOSPAM.yahoo.com>
    Re: Question about News::NNTPClient Module <glex_nospam@qwest.net>
    Re: Question about News::NNTPClient Module <extendedpartition@NOSPAM.yahoo.com>
        Simple Regular Expressions Question (Mike Miller)
    Re: Simple Regular Expressions Question <mthunter@students.uiuc.edu>
    Re: Simple Regular Expressions Question (Walter Roberson)
    Re: Simple Regular Expressions Question <skuo@mtwhitney.nsc.com>
    Re: Simple Regular Expressions Question <krahnj@acm.org>
    Re: strict and warnings <goldbb2@earthlink.net>
    Re: use integer, strange negative results <mthunter@students.uiuc.edu>
    Re: use integer, strange negative results <mthunter@students.uiuc.edu>
    Re: use integer, strange negative results <goldbb2@earthlink.net>
    Re: Using a variable to create a slice <goldbb2@earthlink.net>
    Re: Warnings in modules <noreply@gunnar.cc>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 12 Feb 2003 16:19:21 -0800
From: rshoham@yahoo.com (Ran)
Subject: Re: $q->a( -href ... ) question
Message-Id: <a98ee21f.0302121619.5b8c4cac@posting.google.com>

okay...I figured it out myself. No need to reply.
Here is the solution though if anyone is interested:

print $q->a( { -href => $urldestination, -target = 'NEW' }, "TEXT" ); 


Cheers.


rshoham@yahoo.com (Ran) wrote in message news:<a98ee21f.0302121145.13e8506@posting.google.com>...
> Hello all,
> 
> In HTML I can do the following:
> <A HREF="urldestination" TARGET="NEW">   </A> to open the 
> URL in a new window.
> 
> 
> I wish to do this on my Perl CGI form.  So far I have:
> 
> print $q->a( { -href => $urldestination }, $urldestination );
> 
> 
> 
> But I can't for the life of me figure out how to implement the
> target = "new" in this format.
> 
> Any working ideas welcome.
> 
> 
> Best regards,
> 
> Ran (please reply to rshoham@yahoo.com if possible)


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

Date: 12 Feb 2003 16:18:49 -0800
From: rfrigerio@northropgrumman.com (Robert F.)
Subject: Accessing a remote DB
Message-Id: <4e11f28b.0302121618.28e66c3f@posting.google.com>

We are using Perl on a web server running Win 2000 Server and it is
connected to an Alpha Server running OpenVMS as a file server.  Is
there some way that I can access data from a database on the Alpha
Server?  I need to retrieve and check that a certain value is in a
particular field in one table.  I am new to the whole Perl and
database world so any help would be greatly appreciated.


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

Date: 12 Feb 2003 17:52:44 -0700
From: Eric Schwartz <eric.schwartz@hp.com>
Subject: Re: Accessing a remote DB
Message-Id: <eto7kc5huhv.fsf@wormtongue.emschwar>

rfrigerio@northropgrumman.com (Robert F.) writes:
> We are using Perl on a web server running Win 2000 Server and it is
> connected to an Alpha Server running OpenVMS as a file server.  Is
> there some way that I can access data from a database on the Alpha
> Server?  I need to retrieve and check that a certain value is in a
> particular field in one table.  I am new to the whole Perl and
> database world so any help would be greatly appreciated.

Short answer: yes.

Medium answer: Really, it depends on the database you're running, but
Perl can access most common databases (and several uncommon ones)
using DBI.  Use `perldoc DBI` at a command prompt to find out more.

Long answer: Searching Google for "Perl and Databases" (so
capitalized, because I was looking for an article or presentation
title) brings me to <URL:http://dc.pm.org/talks/perl_db.html>, which
looks like a pretty decent summary of DBI and DBD (read the article,
it'll explain these acronyms).  ORA also sell "Programming the Perl
DBI: Database Programming with Perl", but I haven't read it and can't
comment either way, except to point out it exists.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: 12 Feb 2003 23:42:53 GMT
From: Michael Lapsley <spamtrap@lapsley.ukshells.co.uk>
Subject: binary data and utf8 (I think)
Message-Id: <slrnb4lmvt.3pt.spamtrap@rift.ukshells.co.uk>

Hi,

I have just spent a frustrating evening trying to figure out why
a BMP manipulation program produces corrupt files almost twice
the size they should be on one machine, but not on another.

The culprit machine is running 5.6.1 (linux).  This code fragment
shows the problem:

wrong.pl
===============
#!/usr/bin/perl
no utf8;
use bytes;
$bmpheader="\x{42}\x{4d}\x{be}\x{0c}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{3e}
\x{00}\x{00}\x{00}\x{28}\x{00}\x{00}\x{00}\x{a0}\x{00}\x{00}\x{00}\x{a0}\x{00}
\x{00}\x{00}\x{01}\x{00}\x{01}\x{00}\x{00}\x{00}\x{00}\x{00}\x{80}\x{0c}\x{00}
\x{00}\x{c4}\x{0e}\x{00}\x{00}\x{c4}\x{0e}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}
\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{ff}\x{ff}\x{ff}\x{00}";

binmode(STDOUT);
print $bmpheader;
__END_
===============
$ wrong.pl|xxd

0000000: 424d c2be 0c00 0000 0000 003e 0000 0028  BM.........>...(
0000010: 0000 00c2 a000 0000 c2a0 0000 0001 0001  ................
0000020: 0000 0000 00c2 800c 0000 c384 0e00 00c3  ................
0000030: 840e 0000 0000 0000 0000 0000 0000 0000  ................
0000040: c3bf c3bf c3bf 00                        .......

As you can see this is corrupt all over the place.  no utf8 and
use bytes have no effect.

I've been doing small jobs with perl for a long time, but this is the
first time I've been so thoroughly stumped!  Can anyone help?

perl -V below.

Thanks,

Michael.


Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.4.2-2, archname=i586-linux
    uname='linux dell 2.4.2-2 #1 sun apr 8 19:37:14 edt 2001 i586 unknown '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=
undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing 
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.1 2.96-81)', 
gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, 
Off_t='off_t', lseeksize=8
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldl -lm -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil
    libc=/lib/libc-2.2.2.so, so=so, useshrplib=true, libperl=libperl.so
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, 
ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.6.1/i586-linux/CORE'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  Compile-time options: USE_LARGE_FILES
  Built under linux
  Compiled at Nov 18 2001 19:31:42
  @INC:
    /usr/lib/perl5/5.6.1/i586-linux
    /usr/lib/perl5/5.6.1
    /usr/lib/perl5/site_perl/5.6.1/i586-linux
    /usr/lib/perl5/site_perl/5.6.1
    /usr/lib/perl5/site_perl/5.6.0
    /usr/lib/perl5/site_perl
    .


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

Date: Wed, 12 Feb 2003 20:35:12 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: binary data and utf8 (I think)
Message-Id: <3E4AF650.B0BC9D01@earthlink.net>

Michael Lapsley wrote:
> 
> Hi,
> 
> I have just spent a frustrating evening trying to figure out why
> a BMP manipulation program produces corrupt files almost twice
> the size they should be on one machine, but not on another.
> 
> The culprit machine is running 5.6.1 (linux).  This code fragment
> shows the problem:
[snip]
> I've been doing small jobs with perl for a long time, but this is the
> first time I've been so thoroughly stumped!  Can anyone help?

I don't pretend to understand why the problem occured in the first
place, but you might be able to work around it with the following:

#!/usr/bin/perl -w
# spaces added for clarity.
my $bmpheader = join '', qw(424d be0c 0000 0000
   0000 3e00 0000 2800 0000 a000 0000 a000 0000
   0100 0100 0000 0000 800c 0000 c40e 0000 c40e
   0000 0000 0000 0000 0000 0000 0000 ffff ff00);
binmode STDOUT;
print pack 'H*', $bmpheader;

[untested]

-- 
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
 landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"


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

Date: Thu, 13 Feb 2003 00:22:41 GMT
From: Steven Smolinski <steven.smolinski@sympatico.ca>
Subject: Re: HELP! - error message not making sense
Message-Id: <lzB2a.3196$606.748544@news20.bellglobal.com>

Dartnagnan <cb@sebaw.com> wrote:
> 
> The error message is:
>     Global symbol "$Ftp" requires explicit package name at ftp.plx line 8.

That message is provided courtest of the strict pragma.  Do you have:

  use strict;

in your script that you're not showing us?  Also, you do not have the
variable $Ftp in the script that you showed us.  I don't know how you
expect us to debug code that you don't actually show.

The general answer for that error is to declare the variable in
question, like:

  my $ftp = Net::FTP->new('host');
  $ftp->login('name','pass'); 
  # etc

> The script is:
> 
>     use Net::FTP;
> 
>     $ftp = Net::FTP->new("some.host.name", Debug => 0);
>     $ftp->login("anonymous",'-anonymous@');
>     $ftp->cwd("/pub");
>     $ftp->get("that.file");
>     $ftp->quit;
> 
> Doesn't get much cleaner than that does it?  But it's not working.

Define 'working.'  That looks like the example in the documentation.
There is no 'some.host.name' so what would count as working?

Steve
-- 
Steven Smolinski => http://arbiter.ca/
GnuPG Public Key => http://arbiter.ca/steves_public_key.txt
                 => or email me with 'auto-key' in the subject.
Key Fingerprint  => 08C8 6481 3A7B 2A1C 7C26  A5FC 1A1B 66AB F637 495D


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

Date: 12 Feb 2003 15:47:33 -0800
From: brundlefly76@hotmail.com (Seth Brundle)
Subject: Re: High-speed directory listings
Message-Id: <53e2ec95.0302121547.13656dc6@posting.google.com>

> This will be slightly slower than 3 levels of nested opening and reading
> of directories, but it's much clearer.

Yeah my object is purely speed, as I have literally millions of files.


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

Date: 12 Feb 2003 15:22:28 -0800
From: billw@grizzlymtngifts.com (Bill Werle)
Subject: Re: Perl script to create new user in Linux.
Message-Id: <569b95ca.0302121522.7c6782ac@posting.google.com>

"Kjetil" <kjetil.klove@nrk.no> wrote in message news:<D0p2a.27059$Rc7.389130@news2.e.nsc.no>...
> Hello!
> 
> Does anyone have a Perl-script (or a receipt) to make new Linux-users?  I
> would really appreciate it if I could have a copy :-) Please send a copy of
> answers to my email-adress.  I'm using SUSE 7.3.
> 
> Thanks for any answer :-)
> 
> Best regards
> Kjetil Kløve
> Norway

First post so bear with me. Here's how I've done it within a script on
a debian box. I populated an array from a file formatted as such;
user:pwd.

#You'll need deb package libcrypt-passwdmd5-perl libdigest-md5-perl
#libmd5-perl

use Crypt::PasswdMD5;

$passcrypt = PASSCRYPT($pwd);

#following is all one line
system ("/usr/sbin/useradd -g 100 -d /home/$directoryname -p
$passcrypt -s /bin/false $user");

sub PASSCRYPT {
my $randletter = "(int (rand (26)) + (int (rand (1) + .5) % 2 ? 65 :
97))";
my $salt = sprintf ("%c%c", eval $randletter, eval $randletter);
my $plaintext = shift;
return (unix_md5_crypt($plaintext, $salt));
}

Remember useradd does not create the users home directory like adduser
does. You'll also need to add permission changes etc. into your
script. Hope this helps.

Bill Werle


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

Date: Thu, 13 Feb 2003 00:22:40 -0000
From: gort@LinxNet.com (Jim Seymour)
Subject: Re: Perl+Tk+MySQL for Win32 that *works*?
Message-Id: <v4lpag4f0vja93@corp.supernews.com>

In article <slrnb4leov.cej.randy@theoryx5.uwinnipeg.ca>,
	randy@theoryx5.uwinnipeg.ca (Randy Kobes) writes:
[snip]
> 
> So it sounds like the problem is is that you haven't installed
> mysql itself .... DBD::mysql is just the database driver.
[snip]

One of us (and I can easily believe it's me) is confused.  The
actually MySQL dbm is on another machine.  The following bit of code,
from a very early learning experiment I did, works either against a
MySQL server running on localhost or on any remote host.

------------------------- begin included text --------------------------
#!/usr/bin/perl -w
#
# Simply test ability to connect to a server

use DBD::mysql;

$dataBase="test";
$hostName="localhost";
$userName="nobody";

$dbh = DBI->connect("DBI:mysql:$dataBase:$hostName", "$userName", "") ||
    die "couldn't connect to db server: $!";
$rc = $dbh->disconnect;
print "test: " . ($rc? "succeeded" : "failed") . "\n";
-------------------------- end included text ---------------------------

All I need do is change $hostName to whatever host MySQL is running
on and it works.  (Assuming, of course, that the appropriate grants
exist, the db exists, etc.)

I made the assumption that DBD::mysql was the proper Perl module to
use to accomplish the same end with the Perl port(s) to Win32.  If
it's not, than what is?  And, I might ask, if it's not: why not?
Why would such a thing be done?  (If you know.)

[snip]
>>
>>Dominant... hmph.  Maybe not the best.  Are there others?  The
>>"works," in quotes like that, is not encouraging.  
> 
> I meant that in the context of you asking if ActivePerl
> works .... Yes, it "works", and very well indeed - as
> I also mentioned, look at the activity on the perl-win32
> users mailing list at ActiveState's site, and the types
> of questions being asked there ....

A misunderstanding, then.  I've been experiencing trouble, and you
expressed it as "works."  When something's quoted like that, in that
context, it tends to imply something like "well, kinda sorta."  I
thought you were more-or-less confirming the suspicion I was getting
that the port wasn't all that great.

> 
>>                                                 I note that
>>MySQL, and even DBI, don't appear to be on AS' current module
>>list.  They're no listed at all.  I am not impressed.
> 
> They're in the 6xx repository, but not yet in 8xx, which is
> relatively new .... There's over 5000 distributions on CPAN,
[snip]

Having had to hunt 'em down to build 'em, I'm well-aware :).  The
thing that concerned me was not seeing either DBI or DBD::mysql on
the PPN Module Status list at all.

> 
> As Jeff also expressed in another reply, your attitude
> seems surprising ...

Write it off to severe frustration.  And if I've offended: please
accept my apologies.  In fact: in my last follow-up I neglected to
thank you for your help.  I almost *never* forget to do that.  So
please also accept my belated thanks.

>                      ActiveState is supplying these binaries, 
> ppm packages, and, most of all, their expertise, free of 
> charge, which in the Win32 world is unusual.

Indeed it is.

>                                              Obviously 
> there can be glitches, as with anything, but giving blanket 
> condemnations because you've encountered these problems aren't 
> helpful.

Understood.  And agreed.

>          What would have happened if people had this attitude 
> in the early days of Linux?

Heh.  Don't believe it didn't happen.  And still does.  That doesn't
make it right.  It's not a justification.  People get frustrated and
lash out.  As I've been doing.  I've been on the receiving end.  I
don't like it either.  But it happens.

Regards,
Jim
-- 
Jim Seymour                    | PGP Public Key available at:
WARNING: The "From:" address   | http://www.uk.pgp.net/pgpnet/pks-commands.html
is a spam trap.  DON'T USE IT! |
Use: jseymour@LinxNet.com      | http://jimsun.LinxNet.com


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

Date: Thu, 13 Feb 2003 00:50:12 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Please explain this weird error message
Message-Id: <Pine.LNX.4.53.0302130046330.8502@lxplus093.cern.ch>

On Feb 12, Jeremy Edgell inscribed on the eternal scroll:

> "Alan J. Flavell" <flavell@mail.cern.ch> wrote in message

> > Perhaps the group could also hold a sweepstake on the least
> > useful Subject: header.  SCNR..
>
> I agree with everyone that the manual is  extremely useful; but give those
> of us with modest knowledge of the language and even worse knowledge of the
> manual a little break.

I don't see how that necessarily prevents one from composing
a meaningful subject header for one's problem, though.



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

Date: 12 Feb 2003 19:24:58 -0500
From: Luis Fernandes <elf@ee.ryerson.ca>
Subject: Re: Please explain this weird error message
Message-Id: <x0k7g5c9id.fsf@ee.ryerson.ca>

Thanks for the help, people. 

In retrospect, I deserved that flamage (it's the first time I was
flamed here, but luckily I always wear my asbestos underoos :).

I was looking at that error for the past day, slept on it and still
couldn't figure it out. The message about the HERE document was
throwing me off the track; when, in fact, I was already derailed.



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

Date: 12 Feb 2003 17:59:04 -0800
From: kalinabears@hdc.com.au (Sisyphus)
Subject: Re: PREFIX and LIB args for Makefile
Message-Id: <e615828f.0302121759.79acdcce@posting.google.com>

friedman@math.utexas.edu (Chas Friedman) wrote in message news:<b2dski$12f$1@geraldo.cc.utexas.edu>...
> (Note: I posted the following as a response to a posting a few days ago,
> but I think it may not have been very visible. Please excuse the repeat
> if this was already seen.)
> 
> Something that's confused me for some time: I've seen recommendations
> in various texts to use 
> 
> perl Makefile.PL PREFIX=... and sometimes just(!) perl Makefile.PL LIB=...
> 
> when creating a Makefile used to install a module in a local 
> (i.e. not the standard) directory.
> In fact, it seems that the PREFIX=... version usually seems to be the one
> that is satisfactory, and the LIB=... isn't what is wanted
> but in a few cases I seem to recall that I needed to use both the PREFIX=... and LIB=... together in the command to use the resulting Makefile without 
> errors/problems. To understand the difference, I tried various combinations
> and compared the resulting Makefiles, and there certainly was a difference, but
> the effect of the differences was hard to understand - Makefiles produced
> by Makefile.PL tend to be rather long and difficult (for me) to read.
> 
>  Anyone know what the effect of each of these settings is and when the LIB=
> is useful? 
>  (Note: I do realize that "use lib" is something different and often
> necessary when using modules located in nonstandard places.)
>  Thanks for any comments or info!
>                        chas

See if 'perldoc ExtUtils::MakeMaker' helps. 
There's a section early on in the documentation dealing specifically
with 'LIB=' and 'PREFIX='.

Cheers,
Rob


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

Date: Wed, 12 Feb 2003 17:47:37 -0600
From: "Extended Partition" <extendedpartition@NOSPAM.yahoo.com>
Subject: Question about News::NNTPClient Module
Message-Id: <3e4add78$1_1@nntp2.nac.net>

Hello Everyone,

I'm having a problem using the News::NNTPClient module. Basically, I need to
retreive a list of all newsgroups carried by my server. I notice that the
module implements the "newsgroups" command which retreives a list of all new
groups within a given timespan. However, I need to retreive a comprehensive
list of all the groups regardless of timespan. Does anyone know how to
accomplish this with this module? It's not covered in the doc.

Thanks,
Anthony Saffer





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

Date: Wed, 12 Feb 2003 18:12:50 -0600
From: Jeff D Gleixner <glex_nospam@qwest.net>
Subject: Re: Question about News::NNTPClient Module
Message-Id: <7oB2a.71$6c6.62478@news.uswest.net>

Extended Partition wrote:
> Hello Everyone,
> 
> I'm having a problem using the News::NNTPClient module. Basically, I need to
> retreive a list of all newsgroups carried by my server. I notice that the
> module implements the "newsgroups" command which retreives a list of all new
> groups within a given timespan. However, I need to retreive a comprehensive
> list of all the groups regardless of timespan. Does anyone know how to
> accomplish this with this module? It's not covered in the doc.

Sure seems to be.. check the list() method.

list [...]
With an argument of "active" or with no arguments, this command returns a list 
of valid newsgroups and associated information.



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

Date: Wed, 12 Feb 2003 19:00:17 -0600
From: "Extended Partition" <extendedpartition@NOSPAM.yahoo.com>
Subject: Re: Question about News::NNTPClient Module
Message-Id: <3e4aee52_1@nntp2.nac.net>

> > I'm having a problem using the News::NNTPClient module. Basically, I
need to
> > retreive a list of all newsgroups carried by my server. I notice that
the
> > module implements the "newsgroups" command which retreives a list of all
new
> > groups within a given timespan. However, I need to retreive a
comprehensive
> > list of all the groups regardless of timespan. Does anyone know how to
> > accomplish this with this module? It's not covered in the doc.
>
> Sure seems to be.. check the list() method.
>
> list [...]
> With an argument of "active" or with no arguments, this command returns a
list
> of valid newsgroups and associated information.

Thanks! Just found this too. Guess I need to read a bit more closely.
Thanks!

Anthony




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

Date: 12 Feb 2003 15:29:44 -0800
From: mmiller@motomonkey.com (Mike Miller)
Subject: Simple Regular Expressions Question
Message-Id: <749ff14d.0302121529.7b1cc628@posting.google.com>

How would you solve the following problem?
I would like to write a regular expression to match any string with 4
digits regardless of what else is in the string. For example all the
following would be matches:
778-0
7-8-8-8
242anycharacters i want to enter go here3
iasd9:asd:0@#$#@d40asdf

I have tried a lot of different ways...I think this should be easy but
I can't figure it out.

Thanks,
Mike


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

Date: Wed, 12 Feb 2003 23:34:01 GMT
From: Mike Hunter <mthunter@students.uiuc.edu>
Subject: Re: Simple Regular Expressions Question
Message-Id: <slrnb4lml0.npb.mthunter@ux12.cso.uiuc.edu>

On 12 Feb 2003 15:29:44 -0800, Mike Miller wrote:
>  How would you solve the following problem?
>  I would like to write a regular expression to match any string with 4
>  digits regardless of what else is in the string. For example all the
>  following would be matches:
>  778-0
>  7-8-8-8
>  242anycharacters i want to enter go here3
>  iasd9:asd:0@#$#@d40asdf
>  
>  I have tried a lot of different ways...I think this should be easy but
>  I can't figure it out.

I haven't tested this, but something like

/\d[^\d]*\d[^\d]*\d[^\d]*\d/

a digit, followed by 0 or more digits, then another digit...


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

Date: 12 Feb 2003 23:44:52 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Simple Regular Expressions Question
Message-Id: <b2em9k$4ai$1@canopus.cc.umanitoba.ca>

In article <749ff14d.0302121529.7b1cc628@posting.google.com>,
Mike Miller <mmiller@motomonkey.com> wrote:
:How would you solve the following problem?
:I would like to write a regular expression to match any string with 4
:digits regardless of what else is in the string. For example all the
:following would be matches:

/^(?:\D*\d){4}\D*$/
-- 
   Scintillate, scintillate, globule vivific 
   Fain would I fathom thy nature specific. 
   Loftily poised on ether capacious 
   Strongly resembling a gem carbonaceous.   -- Anon


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

Date: Wed, 12 Feb 2003 16:08:16 -0800
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Simple Regular Expressions Question
Message-Id: <Pine.GSO.4.21.0302121605400.25701-100000@mtwhitney.nsc.com>

On 12 Feb 2003, Mike Miller wrote:

> ...
> I would like to write a regular expression to match any string with 4
> digits regardless of what else is in the string. For example all the
> following would be matches:
> 778-0
> 7-8-8-8
> 242anycharacters i want to enter go here3
> iasd9:asd:0@#$#@d40asdf
> ... 



I would forego the regular expression and use the 'tr' operator:

print $string if (($string =~ tr/0-9/0-9/) >= 4); # 4 or more digits

or 

print $string if (($string =~ tr/0-9/0-9/) == 4); # exactly 4 digits

-- 
Hope this helps,
Steven



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

Date: Thu, 13 Feb 2003 00:22:45 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Simple Regular Expressions Question
Message-Id: <3E4AE521.7B903F63@acm.org>

Mike Miller wrote:
> 
> How would you solve the following problem?
> I would like to write a regular expression to match any string with 4
> digits regardless of what else is in the string. For example all the
> following would be matches:
> 778-0
> 7-8-8-8
> 242anycharacters i want to enter go here3
> iasd9:asd:0@#$#@d40asdf
> 
> I have tried a lot of different ways...I think this should be easy but
> I can't figure it out.

if ( $string =~ tr/0-9// == 4 ) {
    print "The string '$string' has exactly four digits.\n";
    }



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 12 Feb 2003 20:14:56 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: strict and warnings
Message-Id: <3E4AF190.360B290A@earthlink.net>

Abigail wrote:
[snip]
> :}  Hmmh, when you compile some piece of software, do you always
> :)  compile it with debugging flags? I guess you don't because you
> :)  don't like the performance hit and increeasd size of the
> :)  object-code caused by it. I, for one, want my stderr stream to be
> :)  clean when using Perl modules.
> 
> You guessed wrong. I don't write C code very often, but from my latest
> project (more than half a year ago), I had:
> 
>     CFLAGS = -Wall -pedantic-errors -Wpointer-arith -Wstrict-prototypes       \
>              -Wmissing-prototypes -Winline -Wshadow -Wcast-qual -Wcast-align  \
>              -Wwrite-strings -Wconversion -Waggregate-return -Winline -W      \
>              -Wno-unused -Wsign-compare -g

All of these -W options have only compile-time effects, afaik.

The -g option does have an effect on the speed and size of the
resulting binary, though... I'm not quite sure how useful it is in a
production environment, except that it will result in more data in
the core file, if the program segfaults, and it's not unreasonable to
want your users to send you any core file which is produced, so you
can find and fix the bug asap.

In a speed-critical environment, though, I expect that -g would be
left out of the production version, and replaced with -O3 or somesuch.

> in my Makefile.
> 
> It's now happily running at a production cluster of a large bank,
> sending payments to the payments router.

Hmm, sounds IO intensive -- the minor slowdown from -g probably isn't
noticable, since it only effects user-level code, not library calls or
low-level system calls, which is where the IO is actually performed.

PS: Your .sig produces: "o JutPrerclrHtek naahe s" on AS Perl 5.6.1.


-- 
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
 landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"


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

Date: Wed, 12 Feb 2003 23:03:41 GMT
From: Mike Hunter <mthunter@students.uiuc.edu>
Subject: Re: use integer, strange negative results
Message-Id: <slrnb4lks5.b7j.mthunter@ux12.cso.uiuc.edu>

On Wed, 12 Feb 2003 22:45:46 GMT, Jay Tilton wrote:
>  Mike Hunter <mthunter@students.uiuc.edu> wrote:
>  
> : I found this pretty odd:
>  
>  That's only half of the picture.
>  
>  When something surprising happens, describe also what you expected to
>  happen and how it is different from reality.
>  
> : #!/usr/bin/perl -w
> : use strict;
> : use integer;
> : print "".(2149594597/2)."\n";
> : 
> : -1072686349
>  
>  Look at what perl thinks of your integer even before the division.
>  
>      H>perl -le "use integer; print 2149594597 + 0"
>      -2145372699
>  
>  Is your original result less surprising now, or more so?
>  
>  Read the documentation for the integer pragma.  Use Math::BigInt for
>  math operations on integers that can't be represented by a mere 32
>  bits.
  
Thanks.

It's disapointing I didn't get a warning.  It seems like something that
could be done for a literal overflow.


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

Date: Wed, 12 Feb 2003 23:08:54 GMT
From: Mike Hunter <mthunter@students.uiuc.edu>
Subject: Re: use integer, strange negative results
Message-Id: <slrnb4ll5u.b7j.mthunter@ux12.cso.uiuc.edu>

On Wed, 12 Feb 2003 23:03:41 GMT, Mike Hunter wrote:
>  On Wed, 12 Feb 2003 22:45:46 GMT, Jay Tilton wrote:
> >  Mike Hunter <mthunter@students.uiuc.edu> wrote:
> >  
> > : I found this pretty odd:
> >  
> >  That's only half of the picture.
> >  
> >  When something surprising happens, describe also what you expected to
> >  happen and how it is different from reality.
> >  
> > : #!/usr/bin/perl -w
> > : use strict;
> > : use integer;
> > : print "".(2149594597/2)."\n";
> > : 
> > : -1072686349
> >  
> >  Look at what perl thinks of your integer even before the division.
> >  
> >      H>perl -le "use integer; print 2149594597 + 0"
> >      -2145372699
> >  
> >  Is your original result less surprising now, or more so?
> >  
> >  Read the documentation for the integer pragma.  Use Math::BigInt for
> >  math operations on integers that can't be represented by a mere 32
> >  bits.
>    
>  Thanks.
>  
>  It's disapointing I didn't get a warning.  It seems like something that
>  could be done for a literal overflow.

Also, 2149594597 can be represented as 32 bit integer, just not a signed
32 bit integer.  *sigh*.

Mike


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

Date: Wed, 12 Feb 2003 20:26:14 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: use integer, strange negative results
Message-Id: <3E4AF436.483DE1AB@earthlink.net>

Mike Hunter wrote:
[snip]
> > >  Look at what perl thinks of your integer even before the
> > >  division.
> > >
> > >      H>perl -le "use integer; print 2149594597 + 0"
> > >      -2145372699
> > >
> > >  Is your original result less surprising now, or more so?
> > >
> > >  Read the documentation for the integer pragma.  Use Math::BigInt
> > >  for math operations on integers that can't be represented by a
> > >  mere 32 bits.
> >
> >  Thanks.
> >
> >  It's disapointing I didn't get a warning.  It seems like something
> >  that could be done for a literal overflow.
> 
> Also, 2149594597 can be represented as 32 bit integer, just not a
> signed 32 bit integer.  *sigh*.

Try this with perl 5.8.0, which is much more careful about the
distinction between unsigned integers and signed integers.  I *believe*
that your code will work as you had expected.

-- 
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
 landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"


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

Date: Wed, 12 Feb 2003 21:05:39 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Using a variable to create a slice
Message-Id: <3E4AFD73.588BC3BE@earthlink.net>

Terry Bolands wrote:
> 
> Hi,
> 
> I want to do something like this:
> 
>   @array[1,2,3] = (stuff);
> 
> with a variable like this:
> 
>   $v = "1,2,3";
>   @array[$v] = (stuff);
> 
> but it doesn't work.  Can anyone give me a hint?

Either:

   $v = "1,2,3";
   @array[split /,/, $v] = (stuff);

Or:

   @v = (1, 2, 3);
   @array[@v] = (stuff);


-- 
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
 landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"


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

Date: Wed, 12 Feb 2003 23:50:21 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Warnings in modules
Message-Id: <15B2a.70$qB6.286@newsc.telia.net>

These are my conclusions from the discussions in this thread, and the 
thread "strict and warnings", with respect to my own module:

I have decided to enable warnings, since
1) it's good Perl style,
2) I have been convinced that the effect on performance is negligible,
    and
3) the module doesn't generate any warnings that might annoy the users.

I set the $^W variable (local $^W = 1;) instead of using the 'use 
warnings' pragma, since
1) I'm anxious that the module is backwards compatible, and
2) I have no use (in this case) of the flexibility of 'use warnings'.

Thanks all for your comments; hope you think my reasoning makes sense.

/ Gunnar

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



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

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


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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


------------------------------
End of Perl-Users Digest V10 Issue 4560
***************************************


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