[18470] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 638 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 5 14:10:52 2001

Date: Thu, 5 Apr 2001 11:10:26 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <986494225-v10-i638@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 5 Apr 2001     Volume: 10 Number: 638

Today's topics:
    Re: How can I use  a var as part of a regex pattern <joeybach@127.0.0.1>
    Re: How can I use  a var as part of a regex pattern <wuerz@yahoo.com>
    Re: How can I use  a var as part of a regex pattern <joeybach@127.0.0.1>
    Re: How can I use  a var as part of a regex pattern <wuerz@yahoo.com>
    Re: How can I use  a var as part of a regex pattern <ren@tivoli.com>
    Re: How can I use  a var as part of a regex pattern <ren@tivoli.com>
    Re: How can I use  a var as part of a regex pattern nobull@mail.com
        ieee support <nospam@yale.edu>
    Re: ieee support (Anno Siegel)
    Re: Inserting a line in the middle of a file! <js@hotmail.com>
    Re: Inserting a line in the middle of a file! <bmb@ginger.libs.uga.edu>
    Re: maximum value of a list <nospam@hotmail.com>
    Re: Multiple header functions ( )
    Re: NET::SMTP module problems (Anno Siegel)
    Re: NET::SMTP module problems (Tad McClellan)
        newbie : MIME::Lite and attaching files (David Gurney)
        newbie: DBI:ODBC and M/S SQL Server <djmarcus@ex-pressnet.com>
    Re: Newbies welcome (Abigail)
    Re: Please Help ( )
    Re: Please Help <nap@illx.org>
    Re: Regular Expression Help (Easy Question) - Another O <magrav@wnt.sas.com>
    Re: Regular Expression Help (Easy Question) - Another O (Sweth Chandramouli)
    Re: Regular Expression Help (Easy Question) - Another O <ren@tivoli.com>
    Re: Regular Expression Help (Easy Question) - Another O <ren@tivoli.com>
    Re: Regular Expression Help (Easy Question) - Another O <ren@tivoli.com>
    Re: Regular Expression Help (Easy Question) - Another O (Sweth Chandramouli)
    Re: Regular Expression Help (Easy Question) - Another O nobull@mail.com
    Re: Regular Expression Help (Easy Question) ( )
        speed of strings and arrays? <jbehren@gwdg.de>
    Re: speed of strings and arrays? (Anno Siegel)
        using modules over a network <kimmfc@mydeja.com>
        Where to find Register script ? <hugo.b@derivs.com>
    Re: Win32::NetAdmin nobull@mail.com
    Re: Win32::NetAdmin <tsmith@pathnet.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 05 Apr 2001 15:59:33 GMT
From: "John Doe" <joeybach@127.0.0.1>
Subject: Re: How can I use  a var as part of a regex pattern
Message-Id: <FD0z6.36502$Lz6.6235942@typhoon.tampabay.rr.com>

In article <3ACC875A.5C5561AE@si.urv.es>, "Alexis Roda"
<alexis.roda@si.urv.es> wrote:


> eval instead

how would I use the eval()

while (<TEST>){
	if (eval  "/$string/im" ){print } ?

that doesn't seem to work 

when I tried 
#!/usr/bin/perl 

$a = "print $B + $C = $D\n";
$B = 1;
$C = 1;
$D = $B + $C;


eval $a;

it produced  nothing. I read the perldoc and I have the O'Reily's Perl
Books. What am I missing?


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

Date: Thu, 05 Apr 2001 18:06:07 +0200
From: Mona Wuerz <wuerz@yahoo.com>
Subject: Re: How can I use  a var as part of a regex pattern
Message-Id: <050420011806070192%wuerz@yahoo.com>

In article <FD0z6.36502$Lz6.6235942@typhoon.tampabay.rr.com>, "John
Doe" <joeybach@127.0.0.1> wrote:

> when I tried 
> #!/usr/bin/perl 
> 
> $a = "print $B + $C = $D\n";
> $B = 1;
> $C = 1;
> $D = $B + $C;
> 
> 
> eval $a;
> 
> it produced  nothing. I read the perldoc and I have the O'Reily's Perl
> Books. What am I missing?

the -w switch.

You could also try to run this line as a test case:

print $B + $C = $D\n;

and see what you get (and why you don't get what you think you should
get).

-mona


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

Date: Thu, 05 Apr 2001 17:15:12 GMT
From: "John Doe" <joeybach@127.0.0.1>
Subject: Re: How can I use  a var as part of a regex pattern
Message-Id: <AK1z6.36723$Lz6.6281468@typhoon.tampabay.rr.com>

In article <050420011806070192%wuerz@yahoo.com>, "Mona Wuerz"
<wuerz@yahoo.com> wrote:


> In article <FD0z6.36502$Lz6.6235942@typhoon.tampabay.rr.com>, "John Doe"
> <joeybach@127.0.0.1> wrote:
> 
>> when I tried
>> #!/usr/bin/perl
>> $a = "print $B + $C = $D\n";
>> $B = 1;
>> $C = 1;
>> $D = $B + $C;
>> eval $a;
>> it produced  nothing. I read the perldoc and I have the O'Reily's Perl
>> Books. What am I missing?
> the -w switch.
> You could also try to run this line as a test case:  print $B + $C =
> $D\n;
> and see what you get (and why you don't get what you think you should
> get).
> -mona

I tried 
#!/usr/bin/perl -w 

our $D; our $a; our $B; our $C; 
$B = 1;
$C = 1;
$D = ($B + $C);

$a = 'print $B + $C = $D ';


eval ($a);
 
if I add print "$B + $C=$D" it prints.
how can I make eval execute $a as a command ?


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

Date: Thu, 05 Apr 2001 19:21:54 +0200
From: Mona Wuerz <wuerz@yahoo.com>
Subject: Re: How can I use  a var as part of a regex pattern
Message-Id: <050420011921543887%wuerz@yahoo.com>

In article <AK1z6.36723$Lz6.6281468@typhoon.tampabay.rr.com>, "John
Doe" <joeybach@127.0.0.1> wrote:

> I tried 
> #!/usr/bin/perl -w 
> 
> our $D; our $a; our $B; our $C; 
> $B = 1;
> $C = 1;
> $D = ($B + $C);
> 
> $a = 'print $B + $C = $D ';
> 
> 
> eval ($a);
>  
> if I add print "$B + $C=$D" it prints.

Ah! But compare that to what's in $a. Look closely.

> how can I make eval execute $a as a command ?

It already does, it's just that the command you're actually passing is,
uh, not what you think it is.

-mona


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

Date: 05 Apr 2001 12:20:51 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: How can I use  a var as part of a regex pattern
Message-Id: <m34rw3e00c.fsf@dhcp9-175.support.tivoli.com>

On Thu, 05 Apr 2001, joeybach@127.0.0.1 wrote:

> $a = 'print $B + $C = $D ';
> 
> eval ($a);
>  
> if I add print "$B + $C=$D" it prints.
> how can I make eval execute $a as a command ?

That's exactly it.  When you added it directly, you included quotes
around the string to print.  But inside your string to eval, you do
not have the quotes.  In other words, change your assignment to:

$a = 'print "$B + $C = $D\n"';

I added the newline for clean output, but it works without it.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 05 Apr 2001 12:17:36 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: How can I use  a var as part of a regex pattern
Message-Id: <m38zlfe05r.fsf@dhcp9-175.support.tivoli.com>

On Thu, 05 Apr 2001, joeybach@127.0.0.1 wrote:

> What I need to do is match a number of strings within a string . The
> code I have subs the querry to the what I believe is the right
> syntax (it works with hard coded values). But how can I use a
> variable as my matching pattern.  Like $string = "/line/im &&
> /sep/im" if ($_ =~ m$string){print}

You're putting actual code in the string, not just regex stuff --
that's why others have pointed you toward eval.  However, you can
avoid the eval take a slightly different tact:

> The actual code I am using is :
> 
> #!/usr/bin/perl
> open (TEST, "<cisco.log");
> my $string = (<STDIN>);
> chomp $string;
> $string =~ s/ /\/im \&\& \//g;
> print "/$string/im\n";
> 
> while (<TEST>){
> 	if ($_ =~ m/\Q$string\e/im){
> 	print "$_\n";
> 
> 	}
> 	}

So you are breaking up the input string by spaces and want to match
each one separately (and together).  It sounds like you want to match
all of the input words, but in any order, right?

You are appending "im" to each pattern, so you want to ignore case and
also treat the string to match against as if it has multiple lines
(and the pattern as if it has "^" and/or "$" in it).  I see no
evidence that this is true, so I expect you don't really need that "m"
modifier.

So, what we want to do is get the list of words to match, and then
instead of building up $string to try and do everything at once, we'll
just build an array and then loop over it for each line:

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

my @words = split ' ', <>;   # Get words from STDIN
print "Searching for ", join(":", @words), "\n";
open FILE, "cisco.log" or die;
LINE: while (<FILE>) {
  foreach my $word (@words) {
    next LINE unless /\Q$word/i;
  }
  print;
}
__END__


An alternative to this, and closer to your original method, is to use
a lookahead in your regex.  Instead of constructing something like
"/line/im && /sep/im", you would construct something like
"(?=.*line)(?=.*sep)".  With this advanced regex feature, you can
build a single regex that matches all of the provided words in any
order.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 05 Apr 2001 18:21:48 +0100
From: nobull@mail.com
Subject: Re: How can I use  a var as part of a regex pattern
Message-Id: <u9zodvqn2r.fsf@wcl-l.bham.ac.uk>

rgarciasuarez@free.fr (Rafael Garcia-Suarez) writes:

> John Doe wrote in comp.lang.perl.misc:
> > What I need to do is match a number of strings within a string . The code 
> > I have subs the querry to the what I believe is the right  syntax (it works with hard coded
> > values). But how can I use a variable as my matching pattern. 
> > Like $string = "/line/im && /sep/im"
> 
> If you want to embed Perl code in strings, then you should look at the
> eval() function.

s/embed/execute/

If you want to execute code in strings inside a loop you should also
take a look at code references to move the compilation outside the
loop.

# Without a loop (and ignoring errors)
if ( eval $string ) { whatever(); }

# Outside loop
my $code = eval "sub { $string }" or die $@;

# Inside loop
if ( &$code ) { whatever(); }

If the strings in question are being entered by someone who you
wouldn't trust in a command shell then you should take a look at the
Safe module.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 5 Apr 2001 15:07:11 GMT
From: "ivo welch" <nospam@yale.edu>
Subject: ieee support
Message-Id: <9ai1mv$pmn$1@news.ycc.yale.edu>


Is the best way to handle IEEE numbers to first test whether a string
contains the string /nan/ or /inf/?  The normal IEEE suggestion for
identification of NaN
	sub isnan { return ($_[0] != $_[0]); }
gives a non-numeric error.  Having computations that can result in NaN also
leads to all sorts of non-numeric warnings in intermediate computations,
which is quite a pain.  Instead, perl should just realize that NaN and Inf
are numbers.

Is there an addon that makes this magically work?

/iaw


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

Date: 5 Apr 2001 15:45:24 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: ieee support
Message-Id: <9ai3uk$bbr$1@mamenchi.zrz.TU-Berlin.DE>

According to ivo welch <nospam@yale.edu>:
> 
> Is the best way to handle IEEE numbers to first test whether a string
> contains the string /nan/ or /inf/?  The normal IEEE suggestion for
> identification of NaN
> 	sub isnan { return ($_[0] != $_[0]); }
> gives a non-numeric error.  Having computations that can result in NaN also
> leads to all sorts of non-numeric warnings in intermediate computations,
> which is quite a pain.  Instead, perl should just realize that NaN and Inf
> are numbers.

The express purpose of NaN is to indicate that a result is *not* a
number, nor is infinity a number in any sane number system.  Why
would you want to carry on a calculation that is clearly too unstable
to give meaningful numeric results?  You want to be warned when it
happens.  For Perl to treat them as numbers would rob you of that
opportunity.

> Is there an addon that makes this magically work?

It might be desirable in some cases to have them treated specially,
but that would have to be controlled by a pragma so as not to mess
up existing code.  I don't know how common hardware is that implements
NaN and friends, but before it is nearly ubiquitous there is probably
not a big chance that this would be implemented.

Anno


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

Date: Thu, 05 Apr 2001 15:26:15 GMT
From: "Kenneth Eide" <js@hotmail.com>
Subject: Re: Inserting a line in the middle of a file!
Message-Id: <r80z6.1619$CO5.245888@news01.chello.no>

Thanks, i more or less figured out the part on how to create a line like:

#  Name   #  John Smith                                    #

But how would i insert it at the right place in the output file?

> A nice way, but not the more efficient:
>
> $line = sprintf("# Name    # %-50s #", $name);
> ...
>
> adjust the format string according to your needs. Another way, more
> efficient, may be:
>
> $padding = " " x 50;
> $line1 = substr(" # Name   # $name$padding", 0, 50) . "#";
> $line2 = substr(" # Age    # $age$padding", 0, 50) . "#";
> ...
>
>
> HTH
> --
>                                   ////
>                                  (@ @)
> ---------------------------oOO----(_)----OOo------------------------
>         Los pecados de los tres mundos desapareceran conmigo.
> Alexis Roda - Universitat Rovira i Virgili - Reus, Tarragona (Spain)
> --------------------------------------------------------------------




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

Date: Thu, 5 Apr 2001 11:43:04 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Inserting a line in the middle of a file!
Message-Id: <Pine.A41.4.21.0104051140550.16576-100000@ginger.libs.uga.edu>

On Thu, 5 Apr 2001, Kenneth Eide wrote:

> Thanks, i more or less figured out the part on how to create a line like:
> 
> #  Name   #  John Smith                                    #
> 
> But how would i insert it at the right place in the output file?

See perldoc -q "line in a file"

Putting your comments above the comments you're answering is "jeopardy
posting", and you shouldn't do it for a lot of reasons.

Brad



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

Date: Thu, 5 Apr 2001 10:42:15 -0500
From: Mr. SunRay <nospam@hotmail.com>
Subject: Re: maximum value of a list
Message-Id: <sn0z6.149$U65.114919@news.uswest.net>

<snip>

> I feel there should be a list operation to pick the maximum,
> perhaps using 'map', but I can't figure out how.
> Any suggestions?

I haven't benchmarked this, but off the cuff I came up with

@nums = qw(5 7 2 9 6);
map{ $x = $_ if $_ > $x } @nums;
print "High val is $x\n";




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

Date: Thu, 05 Apr 2001 15:40:59 GMT
From: "( ) | 3 ]" <obiwan@mahood.com>
Subject: Re: Multiple header functions
Message-Id: <3ACC921A.9B6D722F@mahood.com>

The way most sites handle this problem is to redirect a user to a thanks page
that has a meta refresh to the file they need to download.  I.e., in your case,
you'd say:

print <<EOF;
Content-type: text/html

<HTML>
<HEAD>
<TITLE>Here's your file!</TITLE>
<META HTTP-EQUIV="Refresh" Content = "2; URL=/cgi-bin/mycgi?someargs">
</HEAD>

<BODY>
A download dialogue box should appear within a few seconds.  If it doesn't,
please <a href="[The same URL that you entered above]">click here</a>.
</BODY>
</HTML>
EOF

Got it?


AW wrote:

> I have a HTML page with a submission form that will POST to a cgi script.
> The script will then set the proper header for a file download.  The file is
> then downloaded.
>
> Problem:
> After the file downloads I would like to print to the screen (thanks for
> downloading, removing the submission form or the like).  Short of that, I
> would accept redirecting to a different url.  Since the header was written
> for "Content-type: application/pdf" I cannot print to the screen or
> redirect.
>
> Do you have a solution?
>
> Application code:
>
> if ($some_test)
>
>     print "Content-type: application/pdf; name=$filename\n";
>     print "Content-Disposition: attachment; filename=$filename\n\n";
>     open(OUTFILE, "$filename");
>        while (<OUTFILE>) {
>              print $_;
>       }
> }
>
> How can I now print to the screen or do a redirect?



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

Date: 5 Apr 2001 15:24:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: NET::SMTP module problems
Message-Id: <9ai2ne$99h$1@mamenchi.zrz.TU-Berlin.DE>

According to Alan Fleming <alan@scotlpuk.com>:
> Hi.  I was using a script which needed this module to send email, and it
> worked fine.  However, i needed to re-install my NT server software, and so
> perl was lost.  When I installed the same version (5.004 I think, and the
> only copy I have) with the same modules, it tells me it cannot find the
> module net::config.  I checked the smpt module, and sure enough, it called
> this module.  I can't find it anywhere, and I do not remember installing
> this at any time in the past.  Is it just a fluke that it worked before, or
> had I accidentally installed it previously?
> 
> Anyway, I really need this module, FAST, 'cos my clients are getting miffed
> by my lack of software for them! :p
> 
> If anybody could reply to me personally (I'll be too busy to check this
> forum again soon) with either info on where to get this module, or a copy of
> it, I'd be very greatful.

Great!  You need it FAST (sic) because your (presumably paying) customers
are stepping on your toes.  So you thought you'd order it on Usenet
to be mailed to you.  Think again.

Anno


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

Date: Thu, 5 Apr 2001 11:17:47 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: NET::SMTP module problems
Message-Id: <slrn9cp34r.j6t.tadmc@tadmc26.august.net>

Alan Fleming <alan@scotlpuk.com> wrote:

>Anyway, I really need this module, FAST, 'cos my clients are getting miffed
>by my lack of software for them! :p


Please do not post job offers in this newsgroup.

Those should go in a newsgroup with "jobs" in the newsgroup name.

(and you neglected to mention the compensation that you are offering)


>If anybody could reply to me personally 


Then nobody else will get to see the answer.

Your selfishness does not mesh well with the concept of "community".


>(I'll be too busy to check this
>forum again soon)


Oh. The "Suicide Sin" ("I don't read this newsgroup"). I have made
the appropriate config file entry. Thank you for identifying yourself.


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


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

Date: Thu, 05 Apr 2001 17:31:01 GMT
From: david_gurney@hotmail.com (David Gurney)
Subject: newbie : MIME::Lite and attaching files
Message-Id: <3acca950.12638763@news.dircon.co.uk>

Hi,
I'm trying to use MIME::Lite to attach files to an email. Using
MIME::Lite sending a normal (singlepart) message is fine and works but
when I try to attach an htm file to it it falls over. Since my webhost
hasn't got MIME::Lite installed on the server I uploaded it (and
MIME::Base64 and MIME::QuotedPrint) inside my cgi-bin and then used
the use lib command to add it to the @INC (if that's how you put it).
Code below - can anyone spot a mistake please ?

if (lc(substr($in{'attach'},length($in{'attach'}) - 4,4)) eq ".doc"){
$DataType = 'application/msword';
}elsif (lc(substr($in{'attach'},length($in{'attach'}) - 4,4)) eq
".pdf"){
$DataType = 'application/pdf';
}elsif (lc(substr($in{'attach'},length($in{'attach'}) - 4,4)) eq
".zip"){
$DataType = 'application/zip';
}elsif (lc(substr($in{'attach'},length($in{'attach'}) - 4,4)) eq
".xls"){
$DataType = 'application/vnd.ms-excel';
}elsif (lc(substr($in{'attach'},length($in{'attach'}) - 4,4)) eq
".ppt"){
$DataType = 'application/vnd.ms-powerpoint';
}elsif (lc(substr($in{'attach'},length($in{'attach'}) - 4,4)) eq
".txt"){
$DataType = 'text/plain';
}elsif (lc(substr($in{'attach'},length($in{'attach'}) - 4,4)) eq
".htm"){
$DataType = 'text/html';
}elsif (lc(substr($in{'attach'},length($in{'attach'}) - 4,4)) eq
"html"){
$DataType = 'text/html';
}else{
$DataType = 'application/octet-stream';
}

$msg = MIME::Lite->new(
			From   =>  "$admin_email",
			To     =>  "$EmailAddress",
			Subject=>  "$in{'subject'}",
			Type   =>  'multipart/mixed',
			Data   =>  "$in{'message'}"
			);


$msg->attach(
		Type     => "$DataType",
		Path     => "temp/$in{'attach'}",
		Filename => "$in{'attach'}"
		);
}
$msg->send("sendmail", "/usr/sbin/sendmail -t -oi -oem");



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

Date: Thu, 5 Apr 2001 11:10:21 -0400
From: "David J. Marcus" <djmarcus@ex-pressnet.com>
Subject: newbie: DBI:ODBC and M/S SQL Server
Message-Id: <tcp2mn12vs5v15@corp.supernews.com>

Hi

I'm running on a Win2K w/SP1 system.

I've searched hi/lo for a clear example on how to connect and use ODBC to
get to an MS/SQL Server database.

I'm trying to connect to a SQL Server system on my local network (resides on
\\SQLSRVR).

I've defined an ODBC data source name using the Control Panel ->
Administrative Tools -> Data Sources (ODBC) -> System DSN

I specified under the Name column: TestDB
the Driver is: SQL Server

In the configuration of the entry the Name shows up correctly as TestDB and
the Server to connect to shows up as SQLSRVR.

When setting up the entry, the testing of the connection indicated that it
was successful (able to interact with the DB).

When I list the available ODBC drivers (using example in Programming the
Perl DBI book), it shows:

Driver: ODBC
        Data Source is DBI:ODBC:Visual FoxPro Database
        . . .
        Data Source is DBI:ODBC:TestDB
        . . .

So I know that the ODBC connection is there.

In my test program I:
        my $conn = DBI->connect( "dbi:ODBC:DSN=TestDB", 'sa', ''') or die...
        my $sth = $conn->prepare( " CREATE TABLE ..."} or die...
        $sth->execute or die...

The connect fails with the following error message:
    DBI->connect(DSN=TestDB) failed: [Microsoft][ODBC Driver Manager] Data
source name not found and no default driver specified (SQL-IM002)(DBD:
db_login/SQLConnect err=-1)

I am suspecting that I am not specifying the DSN properly.

I would love to see a simple example with actual values in the connect
statement corresponding to an ODBC connection to an MS/SQL Server database.

-TIA
David




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

Date: Thu, 5 Apr 2001 17:08:04 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Newbies welcome
Message-Id: <slrn9cp9jk.jda.abigail@tsathoggua.rlyeh.net>

Logan Shaw (logan@cs.utexas.edu) wrote on MMDCCLXXIV September MCMXCIII
in <URL:news:9ahopa$b9d$1@boomer.cs.utexas.edu>:
:} In article <9ahlbv$sf8$1@mamenchi.zrz.TU-Berlin.DE>,
:} Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
:} >> >In article <MqXy6.2$8J2.1187@vic.nntp.telstra.net>,
:} >> >Wyzelli <wyzelli@yahoo.com> wrote:
:} >> >>"A_Geekette" <moiraine{NOSPAM}@qwest.net> wrote in message
:} >> >>news:3ACB0843.24346AEE@qwest.net...
:} >> >>> "Nothing is impossible, no matter how improbable."
:} 
:} >> >>I'd like to see you cut down a Californian Redwod using a banana.
:} >
:} >I'd use the banana to lure...
:} >
:} >Oh...  Can I have more bananas?  A truckload or two?
:} 
:} Well, if given a great quantity of bananas and maybe some rope and
:} string, all you've got to do is keep hanging more and more bananas from
:} the tree, preferably all on one side.  Pretty soon, well... you know
:} what happens to trees in the winter when their branches collect too
:} much ice.


Yeah, the branches break off.



Abigail
-- 
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
                                      print } sub __PACKAGE__ { &
                                      print (     __PACKAGE__)} &
                                                  __PACKAGE__
                                            (                )


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

Date: Thu, 05 Apr 2001 15:57:12 GMT
From: "( ) | 3 ]" <obiwan@mahood.com>
Subject: Re: Please Help
Message-Id: <3ACC95E7.BACDE966@mahood.com>

Sheesh... talk about obvious...

Brad Baxter wrote:

> On Thu, 5 Apr 2001, Waarddebon wrote:
>
> > Why doesn't this work ?
> >
> > $remote2="today";
> > open (THEFILE,"/data1/hm/makers/bezoekers/$remote2");
> > print THEFILE "hi";
> > close THEFILE;
>
> >
>
> Brad



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

Date: Thu, 05 Apr 2001 11:36:42 -0700
From: Nick Pinckernell <nap@illx.org>
Subject: Re: Please Help
Message-Id: <3ACCBB3A.1050400@illx.org>

I'm assuming your trying to write out to a file.
If so, your forgetting the 'mode' for writing.
which is a > in front of the filename in your open
statement.

open(FILEHANDLE, ">$file");

_nick

Waarddebon wrote:

> Why doesn't this work ?
> 
> $remote2="today";
> open (THEFILE,"/data1/hm/makers/bezoekers/$remote2");
> print THEFILE "hi";
> close THEFILE;



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

Date: Thu, 05 Apr 2001 11:22:41 -0400
From: Max Gravitt <magrav@wnt.sas.com>
Subject: Re: Regular Expression Help (Easy Question) - Another One
Message-Id: <2m2pctk1l1361n2v8m0ik41sfr6es65hbe@4ax.com>

Thanks for the response!

How about if I want to match a combination of letters where order
doesn't matter and each letter can only be used 0 or 1 times?

For example, I want to match "FJT", "JFT", "TJF", "T", "TJ", "JT",
"FJ", "F", etc. 

[FJT]* is close, but it allows "FFJT", "FFFFFJJJJJTTTT", etc.

thanks
Max

On Thu, 05 Apr 2001 16:31:43 +0200, Alexis Roda
<alexis.roda@si.urv.es> wrote:

>Max Gravitt wrote:
>> 
>> I'm trying to create a RE that matches numbers 55-99.  My first
>> thought was to do [55-99], but that doesn't work.  Evidently, if you
>> use a range, you can only specify single digits.  "[5-9][0-9]" almost
>> works, except it allows for values 50-54, which I don't want to match.
>
>Try something like:
>
>([6-9][0-9])|(5[5-9])
>
>the first one matches numbers 60-99 and the second 55-59.
>
>
>
>HTH



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

Date: Thu, 05 Apr 2001 16:45:56 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: Regular Expression Help (Easy Question) - Another One
Message-Id: <8j1z6.25670$iU.4807616@news1.rdc1.md.home.com>

In article <2m2pctk1l1361n2v8m0ik41sfr6es65hbe@4ax.com>,
Max Gravitt  <magrav@unx.sas.com> wrote:
>How about if I want to match a combination of letters where order
>doesn't matter and each letter can only be used 0 or 1 times?
>
>For example, I want to match "FJT", "JFT", "TJF", "T", "TJ", "JT",
>"FJ", "F", etc. 
	Should the empty string "" be considered a match,
or not?  Technically, your description above allows it.

	-- Sweth.

-- 
Sweth Chandramouli ; <sweth+perl@gwu.edu>


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

Date: 05 Apr 2001 11:52:27 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Regular Expression Help (Easy Question) - Another One
Message-Id: <m3hf03e1bo.fsf@dhcp9-175.support.tivoli.com>

On 05 Apr 2001, ren@tivoli.com wrote:

> On Thu, 05 Apr 2001, magrav@wnt.sas.com wrote:
> 
>> How about if I want to match a combination of letters where order
>> doesn't matter and each letter can only be used 0 or 1 times?
>> 
>> For example, I want to match "FJT", "JFT", "TJF", "T", "TJ", "JT",
>> "FJ", "F", etc. 
> 
> That one is tricky.
> 
> In Perl, you could do something like:
> 
>   tr/F// <= 1 && tr/J// <=1 && tr/T// <=1
> 
> or:
> 
>   /(?=^[^F]*F?[^F]*$)(?=^[^J]*J?[^J]*$)(?=^[^T]*T?[^T]*$)/

Oops... both of these match additional characters, though the one
below does not.  I knew I had forgotten a test case. :(

> But neither of this is likely to help you in Java.  How about this:
> 
>   /^[FJT]*$/ && /^[^F]*F?[^F]*$/ && /^[^J]*J?[^J]*$/ &&
>   /^[^T]*T?[^T]*$/

Here are fixes for the first two:

  tr/FJT//c == 0 && tr/F// <= 1 && tr/J// <=1 && tr/T// <=1

  /^(?=[^F]*F?[^F]*$)(?=[^J]*J?[^J]*$)[FJ]*T?[FJ]*$/

(I also shortened the second one at the cost of generality.)

For some reason, I ran into trouble with the complement on tr,
getting:

Modification of a read-only value attempted

Not sure why, but a workaround is:

  tr/FJT// == length && tr/F// <= 1 && tr/J// <=1 && tr/T// <=1

or

  /^[FJT]*$/ && tr/F// <= 1 && tr/J// <=1 && tr/T// <=1

-- 
Ren Maddox
ren@tivoli.com


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

Date: 05 Apr 2001 11:39:42 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Regular Expression Help (Easy Question) - Another One
Message-Id: <m3n19ve1wx.fsf@dhcp9-175.support.tivoli.com>

On Thu, 05 Apr 2001, magrav@wnt.sas.com wrote:

> How about if I want to match a combination of letters where order
> doesn't matter and each letter can only be used 0 or 1 times?
> 
> For example, I want to match "FJT", "JFT", "TJF", "T", "TJ", "JT",
> "FJ", "F", etc. 

That one is tricky.

In Perl, you could do something like:

  tr/F// <= 1 && tr/J// <=1 && tr/T// <=1

or:

  /(?=^[^F]*F?[^F]*$)(?=^[^J]*J?[^J]*$)(?=^[^T]*T?[^T]*$)/

But neither of this is likely to help you in Java.  How about this:

  /^[FJT]*$/ && /^[^F]*F?[^F]*$/ && /^[^J]*J?[^J]*$/ && /^[^T]*T?[^T]*$/

-- 
Ren Maddox
ren@tivoli.com


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

Date: 05 Apr 2001 11:53:37 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Regular Expression Help (Easy Question) - Another One
Message-Id: <m3d7are19q.fsf@dhcp9-175.support.tivoli.com>

On Thu, 05 Apr 2001, sweth+perl@gwu.edu wrote:

> 	Should the empty string "" be considered a match,
> or not?  Technically, your description above allows it.

As do my solutions, by the way....

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 05 Apr 2001 17:32:14 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: Regular Expression Help (Easy Question) - Another One
Message-Id: <y_1z6.25765$iU.4817896@news1.rdc1.md.home.com>

In article <m3n19ve1wx.fsf@dhcp9-175.support.tivoli.com>,
Ren Maddox  <ren@tivoli.com> wrote:
>> For example, I want to match "FJT", "JFT", "TJF", "T", "TJ", "JT",
>> "FJ", "F", etc. 
[snip]
>But neither of this is likely to help you in Java.  How about this:
>
>  /^[FJT]*$/ && /^[^F]*F?[^F]*$/ && /^[^J]*J?[^J]*$/ && /^[^T]*T?[^T]*$/
	Well, since Java apps can use ORO and get the full Perl
regex set, why not just use lookahead?  /x(?!.*x)/ matches any
instance of x not followed at any point by another instance of x, or
more colloquially, any unique instance of x.  Toss in a backreference
and a character class, and (assuming as you did that an empty string
is a valid match) /^(([TFJ])(?!.*\2))*$/ should work, and be easily
extendable to any length set of valid characters.  (Replace the * with
a + if the intended use should disallow empty strings.)

	-- Sweth.

-- 
Sweth Chandramouli ; <sweth+perl@gwu.edu>


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

Date: 05 Apr 2001 18:36:10 +0100
From: nobull@mail.com
Subject: Re: Regular Expression Help (Easy Question) - Another One
Message-Id: <u9vgojqmet.fsf@wcl-l.bham.ac.uk>

Max Gravitt <magrav@wnt.sas.com> writes jeopardy-style:

> How about if I want to match a combination of letters where order
> doesn't matter and each letter can only be used 0 or 1 times?
> 
> For example, I want to match "FJT", "JFT", "TJF", "T", "TJ", "JT",
> "FJ", "F", etc. 
> 
> [FJT]* is close, but it allows "FFJT", "FFFFFJJJJJTTTT", etc.

Regular expressions are not good at matching things that _don't_
contain something!

Do you want to located substring matching the above or do you want to
find out if a given string is in the above set?  These are completely
different questions.

If you simply want to find if $string is one of the above (including
"") then:

$string !~ /(.).*\1|[^FJT]/;

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 05 Apr 2001 15:47:23 GMT
From: "( ) | 3 ]" <obiwan@mahood.com>
Subject: Re: Regular Expression Help (Easy Question)
Message-Id: <3ACC939A.86A61AEC@mahood.com>

These guys gave you good answers.  My two cents is that what you call a
"range" is actually called a character class, which explains why it can
only match one character.  In its essence, it's meant to be a group of
chars that are possible matches to a single char, like [fehd35] which
would match any of those 6 characters.  The range thing is kind of a fancy
bell/whistle that cuts down the amount of typing you have to do -- i.e.
[123456789] is the same as [1-9].  The time savings is definitely visibile
when you have something like [a-zA-Z].

If you want to learn more about regex, get a book called "Mastering
Regular Expressions" by Jeffrey Friedl.


Max Gravitt wrote:

> I'm trying to create a RE that matches numbers 55-99.  My first
> thought was to do [55-99], but that doesn't work.  Evidently, if you
> use a range, you can only specify single digits.  "[5-9][0-9]" almost
> works, except it allows for values 50-54, which I don't want to match.
>
> I'm using gnu.regexp java package, which emulates Perl5 regular
> expressions.



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

Date: 05 Apr 2001 17:33:13 +0200
From: Joerg Behrens <jbehren@gwdg.de>
Subject: speed of strings and arrays?
Message-Id: <qgvgojz7ie.fsf@umpp07.gwdg.de>


I know next to nothing about perl internals - even worse, i look
on perl with fortran eyes. I hope this still makes sense to you:

Is it faster to accumulate a large string in one step, like

$large = "";
while(cond1()){
  while(cond2()){
    $large .= tiny_thing();
  }
}


or in medium sized chunks?

$large = "";
while(cond1()){
  $tmp="";
  while(cond2()){
    $tmp .= tiny_thing();
  }
  $large .= $tmp;
}

Or is it faster to use a growing array of substrings (i want to
use the data-structure for simple buffering)?

Using arrays, i wonder if the (push, pop) and (shift,unshift) operators are
of same efficiency. The perlfunc manpage speaks of 'moving everything'
for the latter. I guess, this is just a picture, or?

Are (huge) strings and arrays (with a dynamic history) contiguous in memory,
or twofold addressed and scattered? I think the latter would make sense for
'liquid' data with todays processors, but then again, i am just a fortraner.

Thanks,

Jörg


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

Date: 5 Apr 2001 16:14:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: speed of strings and arrays?
Message-Id: <9ai5ku$ci2$1@mamenchi.zrz.TU-Berlin.DE>

According to Joerg Behrens  <jbehren@gwdg.de>:
> 
> I know next to nothing about perl internals - even worse, i look
> on perl with fortran eyes. I hope this still makes sense to you:
> 
> Is it faster to accumulate a large string in one step, like
> 
> $large = "";
> while(cond1()){
>   while(cond2()){
>     $large .= tiny_thing();
>   }
> }
> 
> 
> or in medium sized chunks?
> 
> $large = "";
> while(cond1()){
>   $tmp="";
>   while(cond2()){
>     $tmp .= tiny_thing();
>   }
>   $large .= $tmp;
> }
> 
> Or is it faster to use a growing array of substrings (i want to
> use the data-structure for simple buffering)?

With Perl this level of optimization is rarely useful.  It is hard
to get strings so large that their copy time actually matters against
the background of Perl's overhead.  If you really want to know, there's
the Benchmark module.

There is some talk about pre-assigning strings that tend to grow long
to save repeated re-allocations, but if you use the string over
again that takes care of itself too.
 
> Using arrays, i wonder if the (push, pop) and (shift,unshift) operators are
> of same efficiency. The perlfunc manpage speaks of 'moving everything'
> for the latter. I guess, this is just a picture, or?

No, it's for real.  A Perl array is an actual array (of pointers to the
scalar values).  The push and pop operators work on the upper end of
the array and take unit time (unless push requires re-allocation).
shift and unshift operate at the beginning and the rest of the array
is copied every time.  Again, arrays are rarely so big that it matters.

> Are (huge) strings and arrays (with a dynamic history) contiguous in memory,
> or twofold addressed and scattered? I think the latter would make sense for
> 'liquid' data with todays processors, but then again, i am just a fortraner.

AFAIK Perl strings must be contiguous.  Unless the hardware and the
C compiler conspire to do scattered storage in an absolute transparent
way, Perl doesn't do it.

Anno


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

Date: Thu, 05 Apr 2001 17:58:17 GMT
From: Kim C <kimmfc@mydeja.com>
Subject: using modules over a network
Message-Id: <jgbpct414mtflj9r33k8vmfhl4n8l5lqjn@4ax.com>

Hi,

Is it possible to use a module located across a network?

I have a module on one machine that queries a database, and I need to
be able to call that module from a script running on another machine.
I've tried the following:  (all-w2k network running latest ActivePerl
on both machines in question).


## Start calling script:
push @INC , '\\some_box\shared_dir' ## location of 'foreign_module.pm'
use foreign_module;

	## Code using subs from 'foreign_module'

## End calling script


This generates the error: 
	"Can't locate foreign_module.pm in @INC..."
and then displays all valid paths in @INC (all are local).  The
network path that was added in the first line of code is not
displayed, though it is there if the contents of @INC are explicitly
printed.  This leads me to believe the paths in @INC are validated
before use and I'm making some kind of error in defining the network
path I need.

The module runs fine when called on a local machine.

Thanks for your help,

Kim


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

Date: Thu, 5 Apr 2001 17:37:18 +0100
From: "hugo botha" <hugo.b@derivs.com>
Subject: Where to find Register script ?
Message-Id: <9ai72u$5daak$1@ID-76766.news.dfncis.de>

Hi all.

I am looking for a perl script that allows members to signup to become a
member and auto receive a username and password.

Any help ?

hugo.b@derivs.com

Thanks




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

Date: 05 Apr 2001 18:22:03 +0100
From: nobull@mail.com
Subject: Re: Win32::NetAdmin
Message-Id: <u9y9tfqn2c.fsf@wcl-l.bham.ac.uk>

"Tony Smith" <tsmith@pathnet.net> writes:

>   Does the UserGetAttribute function in Win32::NetAdmin "have" to be run on
>   a PDC?

No, but the first argument must be a [PB]DC if you are looking at
domain users.

Usually you'd use the GetDomainController() to get the domain
controller rather than specify it explicitly.

>   If I run it on my machine, I get:
> 
>   "The system could not find the environment option that was entered"

Good isn't it?  Personally I prefer Unix's "Invalid argument" error.
At least "invalid argument" doesn't appear to be trying to tell you
anything.

> use Win32::NetAdmin;
> 
> Win32::NetAdmin::UserGetAttributes("PDC",

Change "PDC" to "\\\\PDC".

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 05 Apr 2001 17:55:16 GMT
From: "Tony Smith" <tsmith@pathnet.net>
Subject: Re: Win32::NetAdmin
Message-Id: <8k2z6.1549$Dh2.126491@paloalto-snr1.gtei.net>

yep yep...

\\\\pdc  took care of the problem :)

thanks for your help


<nobull@mail.com> wrote in message news:u9y9tfqn2c.fsf@wcl-l.bham.ac.uk...
> "Tony Smith" <tsmith@pathnet.net> writes:
>
> >   Does the UserGetAttribute function in Win32::NetAdmin "have" to be run
on
> >   a PDC?
>
> No, but the first argument must be a [PB]DC if you are looking at
> domain users.
>
> Usually you'd use the GetDomainController() to get the domain
> controller rather than specify it explicitly.
>
> >   If I run it on my machine, I get:
> >
> >   "The system could not find the environment option that was entered"
>
> Good isn't it?  Personally I prefer Unix's "Invalid argument" error.
> At least "invalid argument" doesn't appear to be trying to tell you
> anything.
>
> > use Win32::NetAdmin;
> >
> > Win32::NetAdmin::UserGetAttributes("PDC",
>
> Change "PDC" to "\\\\PDC".
>
> --
>      \\   ( )
>   .  _\\__[oo
>  .__/  \\ /\@
>  .  l___\\
>   # ll  l\\
>  ###LL  LL\\




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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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