[24966] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7216 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 6 21:09:37 2004

Date: Wed, 6 Oct 2004 18:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 6 Oct 2004     Volume: 10 Number: 7216

Today's topics:
        -d file test using Active State PERL under Windows <usenet739_yahoo_com_au>
    Re: -d file test using Active State PERL under Windows <perl&nntp@rhesa.com>
    Re: @INC [way off topic now]  <mritty@gmail.com>
    Re: finding the last element in a referenced array <Joe.Smith@inwap.com>
        Help with Sending Multiple Emails! <gobeyondgobeyond@Rem0ve.Yahoo.com>
    Re: Help with Sending Multiple Emails! <mritty@gmail.com>
    Re: Help with Sending Multiple Emails! <spam@cuthere-infocopter.ch>
    Re: Help with Sending Multiple Emails! <spam@cuthere-infocopter.ch>
    Re: How to prevent the removal of \ from pairs of \\? <abigail@abigail.nl>
    Re: Is PHP still slower than Perl? (Brad Shinoda)
    Re: Is PHP still slower than Perl? <postmaster@castleamber.com>
        Regex gurus question <http://joecosby.com/code/mail.pl>
    Re: Regex gurus question <abigail@abigail.nl>
    Re: Regex gurus question <noreply@gunnar.cc>
    Re: Regex gurus question <ebohlman@omsdev.com>
    Re: Regex gurus question <tadmc@augustmail.com>
        Running vi from Perl (DrStrangepork)
    Re: Running vi from Perl (Walter Roberson)
    Re: Running vi from Perl <abigail@abigail.nl>
    Re: Running vi from Perl <simon@unisolve.com.au>
    Re: Running vi from Perl <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 7 Oct 2004 09:58:35 +1000
From: "Scott" <usenet739_yahoo_com_au>
Subject: -d file test using Active State PERL under Windows
Message-Id: <41648726$0$1274$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

Hi,

I have this test script:

my $dir = "C:/WINNT";
opendir(DIR,$dir) || die("Cannot open directory $dir");
my @files = readdir DIR;
closedir(DIR);

foreach (@files) {
   print "$_\n" if -d;  # -d -f -t -T -B
}

I've cycled thru the tests as per the comment line above.

Here is the (annotated) output:

C:\Perl\my.scripts>test2  (-d)
 .
 ..

C:\Perl\my.scripts>test2  (-f)

C:\Perl\my.scripts>test2  (-t a bit nonsensical to try but...)
 .
 ..
$NtUninstallKB329115$
$NtUninstallKB820888$
$NtUninstallKB822831$
$NtUninstallKB823182$
$NtUninstallKB824105$
$NtUninstallKB825119$
$NtUninstallKB826232$
$NtUninstallKB828749$
$NtUninstallKB837272$
$NtUninstallKB839643-DirectX9$
$NtUninstallKB839645$
$NtUninstallKB840315$
$NtUninstallKB841872$
$NtUninstallKB841873$
$NtUninstallKB842526$
$NtUninstallQ818043$
$NtUninstallQ828026$
Active Setup Log.txt
(rest deleted)

C:\Perl\my.scripts>test2  (-T)

C:\Perl\my.scripts>test2  (-B)

C:\Perl\my.scripts>

For -d, I would have expected it to list all the directories (only) under 
C:\WINNT.
For -f, I would have expected it to list all the plain files (i.e. 
everything except directories)
For -t, I'm not sure what it should have listed.  The doc says "-t 
Filehandle is opened to a tty."
For -T, I would have expected it to list all the ASCII text files.
For -B, I would have expected it to list all the binary files.

Any idea what I might be doing wrong?  Are my assumptions incorrect?

In my actual script, I have to read a directory, and process only the 
returned directories in that directory.  I'm running ActiveState PERL under 
Windows 2000 Professional.

Here is the version of PERL I'm using:

C:\Perl\my.scripts>perl -V
Summary of my perl5 (revision 5 version 8 subversion 3) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define 
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags 
='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT 
  -DNO_HASH_SEED -DPERL_IMPLICIT_CONTEXT -DPERL_IMPL
ICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
    optimize='-MD -Zi -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', 
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags 
'-nologo -nodefaultlib -debug -opt:ref,icf  -libpath:"C:\Perl\lib\CORE"  -machine:x86'
    libpth=C:\PROGRA~1\MICROS~3\VC98\lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib 
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib 
uuid.lib wsoc
k32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib 
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib 
uuid.lib
wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib 
msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
    gnulibc_version='undef'
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', 
lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf  -libpath:"C:\Perl\lib\CORE" 
  -machine:x86'


Characteristics of this binary (from libperl):
  Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES 
PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
  Locally applied patches:
        ActivePerl Build 809
        22218 Remove the caveat about detached threads crashing on Windows
        22201 Avoid threads+win32 crash by freeing Perl interpreter slightly 
later
        22169 Display 'out of memeory' errors using low-level I/O
        22159 Upgrade to Time::Hires 1.55
        22120 Make 'Configure -Dcf_by=...' work
        22051 Upgrade to Time::HiRes 1.54
        21540 Fix backward-compatibility issues in if.pm
  Built under MSWin32
  Compiled at Feb  3 2004 00:28:51
  @INC:
    C:/Perl/lib
    C:/Perl/site/lib
    .

C:\Perl\my.scripts>

Thanks for the help!

Scott 




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

Date: Thu, 07 Oct 2004 02:29:02 +0200
From: Rhesa Rozendaal <perl&nntp@rhesa.com>
Subject: Re: -d file test using Active State PERL under Windows
Message-Id: <41648dcf$0$78738$e4fe514c@news.xs4all.nl>

Scott wrote:
> Hi,
> 
> I have this test script:
> 
> my $dir = "C:/WINNT";
> opendir(DIR,$dir) || die("Cannot open directory $dir");
> my @files = readdir DIR;
> closedir(DIR);
> 
> foreach (@files) {
>    print "$_\n" if -d;  # -d -f -t -T -B
> }
> 

> C:\Perl\my.scripts>test2  (-d)

[snip]

> Any idea what I might be doing wrong?  Are my assumptions incorrect?

Yes, your assumption about the current working directory.
Next time, try

	print $_,$/ if -d "$dir/$_";


HTH,

Rhesa


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

Date: Wed, 06 Oct 2004 18:09:26 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: @INC [way off topic now] 
Message-Id: <qxW8d.842$sa.485@trndny07>

"Fred Toewe" <ftoewe@austin.rr.com> wrote
>
> "Paul Lalli" <mritty@gmail.com> wrote
> >
> > Isn't ham radio an auditory medium?  How would one audibly convey
"TNX"
> > in such a manner as to be a shortcut for a one-syllable word?
>
> Not initially.  Remember the Morse Code?  Initially, all Ham radio
licenses
> required some degree of proficiency in its use. Now you could say that
was
> auditory, but that's stretching it a bit.

Okay then. I'm clearly showing my lack of age.  Thanks for the
education. :-)

Paul Lalli




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

Date: Wed, 06 Oct 2004 18:45:16 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: finding the last element in a referenced array
Message-Id: <03X8d.342420$Fg5.328020@attbi_s53>

 .rhavin wrote:

> i think i once again outed myself as a c-styler, thinkin
> the minus-first element is the element preceding the zeroth in a
> reference to the middle of an array - i guess now that kind of
> construction is impossible in perl?

Correct.  Arrays are first class citizens in the Perl world; not
merely pointers to memory.  There's really no concept of a
reference to the middle of an array: Perl gives you a single
scalar, or an array slice (which has its own set of array
bounds checking).
	-Joe


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

Date: Wed, 6 Oct 2004 13:54:43 -0500
From: Terry <gobeyondgobeyond@Rem0ve.Yahoo.com>
Subject: Help with Sending Multiple Emails!
Message-Id: <MPG.1bcdfb72c7af13ca9896b3@news.tc.umn.edu>

Hi,

I am new to Perl.  I ran into this problem while trying to send out 2 
messages from a script.  Nearly half the time, the second message didn't 
get sent, while the first message always get sent.  Here is what I did:

# send the 1st message
open (M, "| /usr/sbin/sendmail -t");

print M "To: $address_01\n";
print M "From: $address_from\n";
 ...
# content of 1st message

close (M);


# send the 2nd message
open (M, "| /usr/sbin/sendmail -t");

print M "To: $address_02\n";
print M "From: $address_from\n";
 ...
# content of 2nd message

close (M);


I wonder if this is the right way to implement this.  Is there a way to 
check to see if the messages have been sent successfully?

Thanks in advance for your help!

Terry


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

Date: Wed, 06 Oct 2004 19:25:50 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Help with Sending Multiple Emails!
Message-Id: <2FX8d.2230$Ua.687@trndny01>

"Terry" <gobeyondgobeyond@Rem0ve.Yahoo.com> wrote
> Hi,
>
> I am new to Perl.  I ran into this problem while trying to send out 2
> messages from a script.  Nearly half the time, the second message
didn't
> get sent, while the first message always get sent.  Here is what I
did:
>
> # send the 1st message
> open (M, "| /usr/sbin/sendmail -t");

Always check the return value of open.
open (M, "| /usr/bin/sendmail -t) or die "Cannot open pipe to sendmail:
$!";

>
> print M "To: $address_01\n";
> print M "From: $address_from\n";
>  ...
> # content of 1st message
>
> close (M);
>
>
> # send the 2nd message
> open (M, "| /usr/sbin/sendmail -t");

See above.

>
> print M "To: $address_02\n";
> print M "From: $address_from\n";
>  ...
> # content of 2nd message
>
> close (M);
>
>
> I wonder if this is the right way to implement this.

It's *a* way.  It's probably not the best way.  You'd be far better off
using one of the several available email modules available on the CPAN.

> Is there a way to
> check to see if the messages have been sent successfully?

Not with this method.  All you can check is that the pipe to sendmail
was opened correctly, and that the pipe was closed correctly.  What
sendmail does is out of your control.  That is one of the reasons I
reccomend the emailing modules.

Paul Lalli





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

Date: Wed, 6 Oct 2004 21:33:09 +0200
From: "Reto Hersiczky" <spam@cuthere-infocopter.ch>
Subject: Re: Help with Sending Multiple Emails!
Message-Id: <41644878$0$28018$5402220f@news.sunrise.ch>

Terry,
you had to close and re-open the file handle to Sendmail for each next
message.
Otherwise I'd expect the first e-mail recipient would receive all the output
as a
long thread ;)

A performance issue for the necessary closing after each message should not
be
worth to be considered if you add the "-odq" option (option delivered
queued )
to the Sendmail command:

> open (M, "| /usr/sbin/sendmail -odq -t");

This will give your script the control flow back very quickly and Sendmail
will use just one SMTP session if multiple recipients had the same MX host.

hth
--retoh :)

"Terry" <gobeyondgobeyond@Rem0ve.Yahoo.com> schrieb im Newsbeitrag
news:MPG.1bcdfb72c7af13ca9896b3@news.tc.umn.edu...
> Hi,
>
> I am new to Perl.  I ran into this problem while trying to send out 2
> messages from a script.  Nearly half the time, the second message didn't
> get sent, while the first message always get sent.  Here is what I did:
>
> # send the 1st message
> open (M, "| /usr/sbin/sendmail -t");
>
> print M "To: $address_01\n";
> print M "From: $address_from\n";
>  ...
> # content of 1st message
>
> close (M);
>
>
> # send the 2nd message
> open (M, "| /usr/sbin/sendmail -t");
>
> print M "To: $address_02\n";
> print M "From: $address_from\n";
>  ...
> # content of 2nd message
>
> close (M);
>
>
> I wonder if this is the right way to implement this.  Is there a way to
> check to see if the messages have been sent successfully?
>
> Thanks in advance for your help!
>
> Terry




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

Date: Wed, 6 Oct 2004 21:44:27 +0200
From: "Reto Hersiczky" <spam@cuthere-infocopter.ch>
Subject: Re: Help with Sending Multiple Emails!
Message-Id: <41644b1b$0$28019$5402220f@news.sunrise.ch>

I agree with the previous reply, checkout these CPAN modules first:

Net::SMTP
or
MIME::Lite
(I prefer *this*, see an example on
http://www.infocopter.com/perl/send-htmlmail-multi.htm)

To check if the mail has been accepted, you should hack smth like this:

> > close (M) or die "Message was not accepted $!";

If the mail could be sent or not, had to be checked with the mail log,
usually located at /var/log/maillog

--retoh :)

"Paul Lalli" <mritty@gmail.com> schrieb im Newsbeitrag
news:2FX8d.2230$Ua.687@trndny01...
> "Terry" <gobeyondgobeyond@Rem0ve.Yahoo.com> wrote
> > Hi,
> >
> > I am new to Perl.  I ran into this problem while trying to send out 2
> > messages from a script.  Nearly half the time, the second message
> didn't
> > get sent, while the first message always get sent.  Here is what I
> did:
> >
> > # send the 1st message
> > open (M, "| /usr/sbin/sendmail -t");
>
> Always check the return value of open.
> open (M, "| /usr/bin/sendmail -t) or die "Cannot open pipe to sendmail:
> $!";
>
> >
> > print M "To: $address_01\n";
> > print M "From: $address_from\n";
> >  ...
> > # content of 1st message
> >
> > close (M);
> >
> >
> > # send the 2nd message
> > open (M, "| /usr/sbin/sendmail -t");
>
> See above.
>
> >
> > print M "To: $address_02\n";
> > print M "From: $address_from\n";
> >  ...
> > # content of 2nd message
> >
> > close (M);
> >
> >
> > I wonder if this is the right way to implement this.
>
> It's *a* way.  It's probably not the best way.  You'd be far better off
> using one of the several available email modules available on the CPAN.
>
> > Is there a way to
> > check to see if the messages have been sent successfully?
>
> Not with this method.  All you can check is that the pipe to sendmail
> was opened correctly, and that the pipe was closed correctly.  What
> sendmail does is out of your control.  That is one of the reasons I
> reccomend the emailing modules.
>
> Paul Lalli
>
>
>




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

Date: 06 Oct 2004 23:04:39 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: How to prevent the removal of \ from pairs of \\?
Message-Id: <slrncm8ug7.34g.abigail@alexandra.abigail.nl>

Uri Guttman (uri@stemsystems.com) wrote on MMMMLIV September MCMXCIII in
<URL:news:x7llej522z.fsf@mail.sysarch.com>:
\\ >>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:
\\  
\\   >> So how can I assign '\\foo\bar' to a scalar without having to say
\\   >> '\\\\foo\bar'? Is it possible?
\\  
\\   PL> About the only way I can think of is to use a single-quoted heredoc:
\\  
\\   PL> $path =<<'PATH';
\\   PL> \\foo\bar
\\   PL> PATH
\\  
\\   PL> Note that I don't especially understand why this works.  Why would
\\   PL> single-quoted heredocs not work the same as 'normal' single-quoted
\\   PL> strings?
\\  
\\  because in single quoted strings \ is needed to escape ' and \. in
\\  single quoted heredocs there is no need to escape anything as perl just
\\  scans for the closing token. in normal double quoted heredocs, perl has
\\  to scan for \ escapes like \n and \t so it must handle \\ and it makes
\\  that into just \.
\\  
\\  not that i have ever needed to use \ as data (i choose / path based
\\  systems :), this is a good trick to know.


But the string gotten by the here doc method ends with a newline, while
'\\foo\bar' doesn't. So one would have to chomp that off.


Abigail
-- 
perl -we 'print q{print q{print q{print q{print q{print q{print q{print q{print 
               qq{Just Another Perl Hacker\n}}}}}}}}}'    |\
perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w


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

Date: 6 Oct 2004 14:42:51 -0700
From: oracle.shinoda@gmail.com (Brad Shinoda)
Subject: Re: Is PHP still slower than Perl?
Message-Id: <ad3a63b3.0410061342.780a787c@posting.google.com>

John Bokma <postmaster@castleamber.com> wrote in message news:<Xns9579AAC4C59F6castleamber@130.133.1.4>...
> That's mySQL, not PHP.
> 
> I mean something like:
> 
> $query = "INSERT INTO table VALUES(?, ?, ?)";
> mysql_bla( $query, $a, $b, $c );
> 
> Hence without the quote_she_bang_garbage
>  

I can't believe you can't actually write such a function yourself???

People should always be writing wrapper functions or classes to handle
db connections, to remove such stuff as addslashes()ing. Use
func_num_args() to find out the number of arguments passed to a php
function and func_get_arg([number]) to get the [number]th argument
passed. I've written such a function for myself. Well in fact I use
three classes for handling databases - one abstract "Database" class
for any database, one Database specific class (eg mysql_db for mysql
databases) and a Query class for handling queries in the manner you
suggest. Now I do this:

$sql = "SELECT foo, bar
  FROM table
  WHERE a = ?
  AND b = ?";
$db->query(new Query($sql, $a, $b), __LINE__, __FILE__);

And all query preprocessing is handled by the Query class, and
database connection/query processing/error handling is handled by the
database-specific class.

I use such classes in all my developments. They're written once then
forgotten about, and simply reused where needed.

All I'm saying is that it's really pretty easy to implement many
things yourself, without moaning that the language hasn't done them
for you.


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

Date: 7 Oct 2004 00:19:31 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Is PHP still slower than Perl?
Message-Id: <Xns957AC495EAC76castleamber@130.133.1.4>

oracle.shinoda@gmail.com (Brad Shinoda) wrote in
news:ad3a63b3.0410061342.780a787c@posting.google.com: 

> John Bokma <postmaster@castleamber.com> wrote in message
> news:<Xns9579AAC4C59F6castleamber@130.133.1.4>... 
>> That's mySQL, not PHP.
>> 
>> I mean something like:
>> 
>> $query = "INSERT INTO table VALUES(?, ?, ?)";
>> mysql_bla( $query, $a, $b, $c );
>> 
>> Hence without the quote_she_bang_garbage
> 
> I can't believe you can't actually write such a function yourself???

Sure. I can even write my own improved PHP clone. What's the point?

> People should always be writing wrapper functions or classes to handle
> db connections, to remove such stuff as addslashes()ing. Use
> func_num_args() to find out the number of arguments passed to a php
> function and func_get_arg([number]) to get the [number]th argument
> passed. I've written such a function for myself.

Yes, and everybody has to write wrapper functions. You get the point 
now, or do you want it spelled out?

> Well in fact I use
> three classes for handling databases - one abstract "Database" class
> for any database,

Yes, in Perl that is called DBI. You don't have to write it yourself.


> one Database specific class (eg mysql_db for mysql
> databases) and a Query class for handling queries in the manner you
> suggest. Now I do this:
> 
> $sql = "SELECT foo, bar
>   FROM table
>   WHERE a = ?
>   AND b = ?";
> $db->query(new Query($sql, $a, $b), __LINE__, __FILE__);
> 
> And all query preprocessing is handled by the Query class, and
> database connection/query processing/error handling is handled by the
> database-specific class.
> 
> I use such classes in all my developments. They're written once then
> forgotten about, and simply reused where needed.

Wonderful. With Perl it's put on CPAN and used (and tested) by many 
people.

> All I'm saying is that it's really pretty easy to implement many
> things yourself, without moaning that the language hasn't done them
> for you.

Programming shouldn't be about reinventing wheels, and worse reinventing 
bugs.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                           personal page:       http://johnbokma.com/
        Experienced programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html


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

Date: Wed, 06 Oct 2004 16:10:18 -0700
From: Joe Cosby <http://joecosby.com/code/mail.pl>
Subject: Regex gurus question
Message-Id: <fdu8m0lglk1hrjif9jobitfplalp28dj58@4ax.com>


I have a string which will always contain a letter followed by
numbers, eg "x12345"

I want to take the numbers and put them in another variable.

So I do this:

$test = "x12345";

$_ = $test;
m/(\d+)/;
$justTheNumbers = $1;

print "justTheNumbers is $justTheNumbers\n";


and that works, $justTheNumbers is "12345", which is what I want.

The three-line way I do it seems retarded to me though.  Is there a
simpler way to do it?

I mean, something that would occur more or less naturally to somebody
more familiar with Perl and Regex?  I suppose there's always some
simpler way to do anything ... it seems like I must be missing
something obvious though.



-- 
Joe Cosby
http://joecosby.com/ 
YOU can be more like "Bob" than you are now!

http://www.subgenius.com
 


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

Date: 06 Oct 2004 23:13:59 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Regex gurus question
Message-Id: <slrncm8v1n.34g.abigail@alexandra.abigail.nl>

Joe Cosby () wrote on MMMMLIV September MCMXCIII in
<URL:news:fdu8m0lglk1hrjif9jobitfplalp28dj58@4ax.com>:
,,  
,,  I have a string which will always contain a letter followed by
,,  numbers, eg "x12345"
,,  
,,  I want to take the numbers and put them in another variable.
,,  
,,  So I do this:
,,  
,,  $test = "x12345";
,,  
,,  $_ = $test;
,,  m/(\d+)/;
,,  $justTheNumbers = $1;
,,  
,,  print "justTheNumbers is $justTheNumbers\n";
,,  
,,  
,,  and that works, $justTheNumbers is "12345", which is what I want.
,,  
,,  The three-line way I do it seems retarded to me though.  Is there a
,,  simpler way to do it?


Yes, it can easily be done in one line. But that's a simple question,
not a guru question. Nevertheless, a guru answer is hidden in this 
posting.


Abigail
-- 
print "\x28\x24\x6a\x75\x73\x74\x54\x68\x65\x4e\x75\x6d\x62\x65\x72\x73\x29";
print "\x20\x3d\x20\x24\x74\x65\x73\x74\x20\x3d\x7e\x20\x2f\x5c\x64\x2b\x2f\x67"


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

Date: Thu, 07 Oct 2004 01:25:41 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Regex gurus question
Message-Id: <2sjd6jF1hebvaU1@uni-berlin.de>

Joe Cosby wrote:
> I have a string which will always contain a letter followed by
> numbers, eg "x12345"
> 
> I want to take the numbers and put them in another variable.
> 
> So I do this:
> 
> $test = "x12345";
> 
> $_ = $test;
> m/(\d+)/;
> $justTheNumbers = $1;
> 
> print "justTheNumbers is $justTheNumbers\n";
> 
> and that works, $justTheNumbers is "12345", which is what I want.
> 
> The three-line way I do it seems retarded to me though.  Is there a
> simpler way to do it?

You can do it in one step:

     ($justTheNumbers) = $test =~ /(\d+)/;

Or, if the only thing you need to do is cutting off the first character:

     $justTheNumbers = substr $test, 1;

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


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

Date: 6 Oct 2004 23:56:12 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: Regex gurus question
Message-Id: <Xns957AC192A3AC3ebohlmanomsdevcom@130.133.1.4>

Joe Cosby <http://joecosby.com/code/mail.pl> wrote in 
news:fdu8m0lglk1hrjif9jobitfplalp28dj58@4ax.com:

> 
> I have a string which will always contain a letter followed by
> numbers, eg "x12345"

s/will/is supposed to/;

Good programmers never say "always" or "never."  hehehe.  Unless you do 
only trivial programming, Mr. Murphy is going to pay you several visits.  
You need to get in the habit of making your habitat unattractive to him.

> I want to take the numbers and put them in another variable.
> 
> So I do this:
> 
> $test = "x12345";
> 
> $_ = $test;
> m/(\d+)/;
> $justTheNumbers = $1;

The big problem here (other than the awkwardness of the code) is that if 
Mr. Murphy does show up at your door, $justTheNumbers will contain a value 
that might *look* OK, but really isn't.  For example, if you got a string 
with *no* numbers in it, $justTheNumbers would get the numbers from the 
last good string instead.  If you got a string like "x12a345" it would get 
"12" which is misleading.

A general rule is that if you're using capturing parentheses, do *not* make 
use of the $digit variables unless you've actually tested to make sure the 
match succeeded.  Note that a list assignment from a match, as in Gunnar's 
first solution, takes care of this; if the match fails, the result will be 
undef rather than junk.

The philosophy of "defensive programming" suggests that you should write

($justTheNumbers) = $test =~ /^[[:alpha:]](/d+)$/ or die "unexpected format 
in \$test: [$test]";

It may *look* like a lot of extra effort, but scores of programmers have 
found that the few extra minutes of coding that such techniques entail 
saved them many *hours* of time wasted tracking down subtle bugs. 

I'll admit, though, that Gunnar's second solution (sloppier, but at least 
it will result in an empty string if there are no digits) was the first 
thing that came to my mind.


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

Date: Wed, 6 Oct 2004 18:46:12 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Regex gurus question
Message-Id: <slrncm90u4.87l.tadmc@magna.augustmail.com>

Joe Cosby <> wrote:

> Subject: Regex gurus question
                 ^^^^^

Many people will take offense at your attempt to trick them into
reading your article.

Some people will never see your post because so many others
have tricked them by claiming the need a guru when all they
need is straight-forward code that they have killfiled all 
articles that contain "guru".

Have you seen the Posting Guidelines that are posted here frequently?


> I want to take the numbers and put them in another variable.


You can do that by putting the m// in list context, read up on
the m// operator in

   perldoc perlop


> m/(\d+)/;
> $justTheNumbers = $1;


You should never use the dollar-digit variables unless you have
first ensured that the match *succeeded*.

   if ( m/(\d+)/ ) {
      $justTheNumbers = $1;
   }


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


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

Date: 6 Oct 2004 14:23:25 -0700
From: rickKasten@gmail.com (DrStrangepork)
Subject: Running vi from Perl
Message-Id: <a4cf4e10.0410061323.789d8f39@posting.google.com>

I wrote a script from which I sometimes launch a system command.  In
Win32, this system call launches Notepad, but in Linux it must launch
vi.  It does, but I get a warning "Vim: Warning: Output is not to a
terminal".  vi is there, because the commands work (like :q exits and
I am returned to my perl script), but like the warning says, no
output.  How can I resolve this problem?


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

Date: 6 Oct 2004 22:45:27 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Running vi from Perl
Message-Id: <ck1si7$e16$1@canopus.cc.umanitoba.ca>

In article <a4cf4e10.0410061323.789d8f39@posting.google.com>,
DrStrangepork <rickKasten@gmail.com> wrote:
:I wrote a script from which I sometimes launch a system command.  In
:Win32, this system call launches Notepad, but in Linux it must launch
:vi.  It does, but I get a warning "Vim: Warning: Output is not to a
:terminal". 

What's your stdin and stdout for the 'vi' command that you are
system()'ing ? Are you taking care to redirect the I/O in the
command line that you are sending to system() ? Are you using
a dup/fork/dup/system setup to get the stdin of your perl script
to be the stdin of the system() command? Are you redirecting
  < /dev/tty > /dev/tty   ? Are you stat'ing your perl stdin
to find out whether it is a character device, running through /dev
to find the matching device name for that major/minor combination,
and redirecting from/to that in your system() ? How do you want
your program to gracefully happen the cases where there is no
terminal available (e.g., batch job, or you've managed to become
detached from a controlling terminal), or where your perl
script has stdin or stdout redirected to/from a pipe or file?
-- 
   I wrote a hack in microcode,
   with a goto on each line,
   it runs as fast as Superman,
   but not quite every time!                 -- Don Libes et al.


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

Date: 06 Oct 2004 23:07:31 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Running vi from Perl
Message-Id: <slrncm8ulj.34g.abigail@alexandra.abigail.nl>

DrStrangepork (rickKasten@gmail.com) wrote on MMMMLIV September MCMXCIII
in <URL:news:a4cf4e10.0410061323.789d8f39@posting.google.com>:
==  I wrote a script from which I sometimes launch a system command.  In
==  Win32, this system call launches Notepad, but in Linux it must launch
==  vi.  It does, but I get a warning "Vim: Warning: Output is not to a
==  terminal".  vi is there, because the commands work (like :q exits and
==  I am returned to my perl script), but like the warning says, no
==  output.  How can I resolve this problem?


Change line 17.



Abigail
-- 
perl -wle'print"Κυστ αξοτθες Πεςμ Θαγλες"^"\x80"x24'


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

Date: Thu, 07 Oct 2004 09:30:01 +1000
From: Simon Taylor <simon@unisolve.com.au>
Subject: Re: Running vi from Perl
Message-Id: <ck1vge$qgd$1@otis.netspace.net.au>

DrStrangepork wrote:
> I wrote a script from which I sometimes launch a system command.  In
> Win32, this system call launches Notepad, but in Linux it must launch
> vi.  It does, but I get a warning "Vim: Warning: Output is not to a
> terminal".  vi is there, because the commands work (like :q exits and
> I am returned to my perl script), but like the warning says, no
> output.  How can I resolve this problem?

It sounds like the output of vim is being redirected into a pipe.

Your problem would be a lot easier for people here to comment on if you 
posted a small code sample, that clearly demonstrates the problem

Hope to hear from you soon.

Regards,

Simon Taylor


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

Date: Wed, 6 Oct 2004 18:48:33 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Running vi from Perl
Message-Id: <slrncm912h.87l.tadmc@magna.augustmail.com>

DrStrangepork <rickKasten@gmail.com> wrote:
> I wrote a script from which I sometimes launch a system command.  In
> Win32, this system call launches Notepad, but in Linux it must launch
> vi.  It does, but I get a warning "Vim: Warning: Output is not to a
> terminal".  vi is there, because the commands work (like :q exits and
> I am returned to my perl script), but like the warning says, no
> output.  How can I resolve this problem?


By changing your code.

(If you want to know how your code needs to be changed, you will
 need to show us the code in question, we are not mind readers.
)


Have you seen the Posting Guidelines that are posted here frequently?


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


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

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


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

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


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