[16818] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4230 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 5 21:05:32 2000

Date: Tue, 5 Sep 2000 18:05:16 -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: <968202315-v9-i4230@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 5 Sep 2000     Volume: 9 Number: 4230

Today's topics:
        Alarm function and cgi.pm xlr6drone@my-deja.com
        CGI.pm: controlling Back & Reload <kj0@mailcity.com>
    Re: CGI.pm: controlling Back & Reload (David Efflandt)
    Re: Deadline to meet, configuring ActivePerl, Win98, PW <bart.lateur@skynet.be>
        Dumping lexical data structures from scratchpads <mr_joesixpack@yahoo.com>
        How? Read a file from another server? <webmaster@cobnet.com>
    Re: How? Read a file from another server? (Craig Berry)
    Re: Input problem <mtaylorlrim@my-deja.com>
    Re: Input problem (Mike Stok)
    Re: intranet using perl cgi <bart.lateur@skynet.be>
    Re: IPC::Shareable "Munged shared memory segment" error <jthomas@woodland.org>
    Re: Monitoring a network (Tony L. Svanstrom)
    Re: Monitoring a network (Homer Simpson)
        My Perl got better. So I made this <tom@webign.co.uk>
        Pattern matching <post@svenrixen.de>
    Re: Pattern matching <stephenk@cc.gatech.edu>
    Re: Stable sorting <bart.lateur@skynet.be>
    Re: Stable sorting (Randal L. Schwartz)
    Re: Stable sorting (Randal L. Schwartz)
        string parsing/pattern matching smehta60@my-deja.com
        UDP Broadcast does not work <kiwi@kiwinet.de>
        uninitialized value - but I have initilised it! Haven't <linux@wizdom.org.uk>
    Re: use strict: why? (Andrew Johnson)
    Re: using perl in a redundant way. <bcaligari@my-deja.com>
    Re: using perl in a redundant way. (Andrew Johnson)
    Re: version problem? <bcaligari@my-deja.com>
    Re: Win32 Registry and IP addresses. <mischief@motion.net>
    Re: World Wide PERL PROGRAMMERS TELECOMMUTE <exit72@excite.com>
    Re: World Wide PERL PROGRAMMERS TELECOMMUTE (Maggert)
    Re: World Wide PERL PROGRAMMERS TELECOMMUTE (Tony L. Svanstrom)
    Re: World Wide PERL PROGRAMMERS TELECOMMUTE (Tony L. Svanstrom)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 06 Sep 2000 00:24:14 GMT
From: xlr6drone@my-deja.com
Subject: Alarm function and cgi.pm
Message-Id: <8p42qu$rff$1@nnrp1.deja.com>

The Apache server I work with runs Perl 5.6.0

I'm trying to get a basic script to work that uses cgi.pm (it's one of
the scripts from Lincoln Stein's book CGI.pm)

He mentioned in the book that some servers may not be able handle the
alarm fucntion.  When I tried running the script I got the following
errors from the server logs.

----------

Too many arguments for lock at /users/www/domains/mcreative.com/cgi-bin/
cgipm/guestbook.pl line 102, near "1)"

Too many arguments for lock at /users/www/domains/mcreative.com/cgi-bin/
cgipm/guestbook.pl line 126, near "0)"

Execution of /users/www/domains/mcreative.com/cgi-bin/cgipm/guestbook.pl
aborted due to compilation errors.

[Tue Sep 5 17:09:41 2000] [error] [client 205.178.47.42] Premature end of
script headers: /users/www/domains/mcreative.com/cgi-bin/cgipm/
guestbook.pl

--------
Could lack of support for the alarm function be the culprit or is it
somehting else.  Here is the code for the script.  Any suggestions would
be greatly appreciated.

-----------

#!/usr/bin/perl
# guestbook.pl

require 'CGI.pm';

use CGI qw/:standard :html3 :netscape/;
use POSIX;

@REQUIRED = qw/name e-mail/;
@OPTIONAL = qw/location comments/;
$TIMEOUT = 10;  # allow up to 10 seconds for waiting on a locked
guestbook
$GUESTBOOKFILE = "/users/www/domains/mcreative.com/html/test/
guestbookfile.txt";
%ENTITIES = ('&'=>'&amp;', '>'=>'&gt;', '<'=>'&lt;', '\"'=>'&quot;' );

print header,
    start_html('Guestbook'),
    h1("Guestbook");

$_ = param('action');

 CASE: {
     /^sign/i and do    { sign_guestbook(); last CASE; };
     /^confirm/i and do { write_guestbook() and view_guestbook(); last
CASE; };
     /^view/i and do    { view_guestbook(); last CASE; };
     # default
     generate_form();
 }

sub sign_guestbook {
    my @missing = check_missing(param());
    if (@missing) {
        print_warning(@missing);
        generate_form();
        return undef;
    }
    my @rows;
    foreach (@REQUIRED,@OPTIONAL) {
        push(@rows,TR(th({-align=>LEFT},$_),td(escapeHTML(param($_)))));
    }
    print "Here is your guestbook entry.  Press ",
          em('Confirm')," to save it, or ",em('Change'),
          " to change it.",
          hr,
          table(@rows),
          hr;

    print start_form;
    foreach (@REQUIRED,@OPTIONAL) {
        print hidden(-name=>$_);
    }
    print submit(-name=>'action',
                 -value=>'Change Entry'),
          submit(-name=>'action',
                 -value=>'Confirm Entry'),
          end_form;
}

print end_html;

sub check_missing {
    my (%p);
    grep (param($_) ne '' && $p{$_}++,@_);
    return grep(!$p{$_},@REQUIRED);
}

sub print_warning {
    print font({-color=>'red'},
          'Please fill in the following fields: ',
          em(join(', ',@_)),
          '.');
}

sub generate_form {
    print start_form,
     table(
        TR({-align=>LEFT},
          th('Your name'),
          td(textfield(-name=>'name',-size=>50))
        ),
        TR({-align=>LEFT},
          th('Your e-mail address'),
          td(textfield(-name=>'e-mail',-size=>50))
        ),
        TR({-align=>LEFT},
          th('Your location (optional)'),
          td(textfield(-name=>'location',-size=>50))
        ),
        TR({-align=>LEFT},
          th('Comments (optional)'),
          td(textarea(-name=>'comments',-rows=>4,
                      -columns=>50,
                      -wrap=>1))
        )
     ),
     br,
     submit(-name=>'action',-value=>'View Guestbook'),
     submit(-name=>'action',-value=>'Sign Guestbook'),
     end_form;
}

sub write_guestbook {
    my $fh = lock($GUESTBOOKFILE,1);
    unless ($fh) {
       print strong('Sorry, an error occurred: unable to open guestbook
file.'),p();
       Delete('action');
       print a({-href=>self_url},'Try again');
       return undef;
    }
    my $date = strftime('%D',localtime);
    print $fh join("\t",$date,map {CGI::escape(param($_))}
(@REQUIRED,@OPTIONAL)),"\n";
    print $fh "\n";
    print "Thank you, ",param('name'),", for signing the guestbook.\n",
      p(),
      a({href=>"../source.html"},'Code Examples');
    unlock($fh);
    1;
}

sub view_guestbook {

    print start_form,
          submit(-name=>'Sign Guestbook'),
          end_form
          unless param('name');

    my $fh = lock($GUESTBOOKFILE,0);

    my @rows;
    unless ($fh) {
       print strong('Sorry, an error occurred: unable to open guestbook
file.'),br;
       Delete('action');
       print a({-href=>self_url},'Try again');
       return undef;
    }
    while (<$fh>) {
       chomp;
       my @data = map {CGI::unescape($_)} split("\t");
       foreach (@data) { $_ = escapeHTML($_); }
       unshift(@rows,td(\@data));
    }
    unshift(@rows,th(['Date',@REQUIRED,@OPTIONAL]));
    print table({-border=>''},
          caption(strong('Previous Guests')),
          TR(\@rows));
    print p,a({href=>"../source.html"},'Code Examples');
    1;
}

sub escapeHTML {
    my $text = shift;
    $text =~ s/([&\"><])/$ENTITIES{$1}/ge;
    return $text;
}

sub LOCK_SH { 1 }
sub LOCK_EX { 2 }
sub LOCK_UN { 8 }

sub lock {
    my $path = shift;
    my $for_writing = shift;

    my ($lock_type,$path_name,$description);
    if ($for_writing) {
        $lock_type = LOCK_EX;
        $path_name = ">>$path";
        $description = 'writing';
    } else {
        $lock_type = LOCK_SH;
        $path_name = $path;
        $description = 'reading';
    }

    local($msg,$oldsig);
    my $handler = sub { $msg='timed out'; $SIG{ALRM}=$oldsig; };
    ($oldsig,$SIG{ALRM}) = ($SIG{ALRM},$handler);
    alarm($TIMEOUT);

    open (FH,$path_name) or
       warn("Couldn't open $path for $description: $!"), return undef;

    # now try to lock it
    unless (flock (FH,$lock_type)) {
       warn("Couldn't get lock for $description (" . ($msg || "$!") .
")");
       alarm(0);
       close FH;
       return undef;
    }

    alarm(0);
    return FH;
}

sub unlock {
    my $fh = shift;
    flock($fh,LOCK_UN);
    close $fh;
}


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 5 Sep 2000 18:26:55 -0400
From: kj0 <kj0@mailcity.com>
Subject: CGI.pm: controlling Back & Reload
Message-Id: <8p3rvf$ccr$1@panix3.panix.com>



I'm using CGI.pm to write a CGI application that causes new records to
be entered in a database.  The structure of the site is

                  [ok]            [submit]
  Data Entry page  --> Review page   --> Confirmation page

All pages are generated by the same perl script.  I would like to
arrange things such that, if the user is at the Confirmation page,
hitting the "Back" button will send him/her to the page visited before
the Data Entry page.  (Currently, hitting the "Back" button while
visiting the Confirmation page sends the user to the Review page.)

Is there a way to do this?

Or else, is there any way to tell if a page has been reached via the
Back button?

Thanks!


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

Date: Wed, 6 Sep 2000 00:31:45 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: CGI.pm: controlling Back & Reload
Message-Id: <slrn8rb43g.35n.efflandt@efflandt.xnet.com>

On 5 Sep 2000 18:26:55 -0400, kj0 <kj0@mailcity.com> wrote:
>
>I'm using CGI.pm to write a CGI application that causes new records to
>be entered in a database.  The structure of the site is
>
>                  [ok]            [submit]
>  Data Entry page  --> Review page   --> Confirmation page
>
>All pages are generated by the same perl script.  I would like to
>arrange things such that, if the user is at the Confirmation page,
>hitting the "Back" button will send him/her to the page visited before
>the Data Entry page.  (Currently, hitting the "Back" button while
>visiting the Confirmation page sends the user to the Review page.)
>
>Is there a way to do this?

The first time the script is accessed with no parameters (to generate the
first form), test the referer() and set it to a default (like your home
page) if referer() does not have a value.  Then pass this as a hidden
variable through your forms and use that for your own back link on the
last form (assuming CGI.pm function mode).

# Only before printing first form
$_ = referer() || 'http://some_default_url/';
param('referer',$_);

# Withinn all forms including the first
print hidden('referer');

# Any place you want a back link
print a({href=>param('referer')},'Back to " . param('referer'));

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/  http://cgi-help.virtualave.net/



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

Date: Tue, 05 Sep 2000 22:10:53 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Deadline to meet, configuring ActivePerl, Win98, PWS 4.0
Message-Id: <8orarsgnl7ceb8gmov5c6ns3uub48u48vm@4ax.com>

Sean Kearney wrote:

>Why would a Perl script work under NT running IIS and Perl 5, but not
>under Win98 PWS4.0 running Perl 5?
>I am getting errors that say the CGI application are not returning a
>complete set of HTTP headers.

Difference between server softwares, so it seems. Most servers only need
a valid content-type header.

If there are any warnings printed out before this header is sent, you
can get this kind of behaviour. You could try to print out this header
first thing you do.

-- 
	Bart.


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

Date: Tue, 05 Sep 2000 23:09:05 GMT
From: Paul Laub <mr_joesixpack@yahoo.com>
Subject: Dumping lexical data structures from scratchpads
Message-Id: <8p3ue5$mih$1@nnrp1.deja.com>

Dear all,

I want a utility like dumpvar.pl to dump out all lexical (ie., "my")
data structures in the current block of code. Because these data
structures are stored in scratchpads, not a package's symbol table, I
don't know how to get at them. Again, I want to dump ALL lexical
data structures without having to name them.

Such a module is meant to record the state of the system when trouble
is detected.

Paul

P.S. Potential flame meisters: I have consulted the perl FAQ, searched
www.perl.com, perused several Perl books, RTFM, and all of that ...


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 05 Sep 2000 22:17:43 GMT
From: leonardz <webmaster@cobnet.com>
Subject: How? Read a file from another server?
Message-Id: <8p3rdp$j80$1@nnrp1.deja.com>

I would like to read a file from another server into my perl script.
I have tried:

@DataFile = ();
$FileName = "http://www.somesite.com/file.dta";

open (DATAFILE, "<$FileName");
  chomp (@DataFile = (<DATAFILE>));
close (DATAFILE);

but as you can guess it does not work?

Can anyone help me here, I don't won't to download the file, only read
it.  If this isn't possible, let me know so I can quit chasing a dream
here, lol.

Thanks for any help that may come my way.
leonardz



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 05 Sep 2000 23:35:28 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: How? Read a file from another server?
Message-Id: <srb0q0ooljn42@corp.supernews.com>

leonardz (webmaster@cobnet.com) wrote:
: I would like to read a file from another server into my perl script.

There are several ways to do this, depending on how the other server is
making the file available.  If it's on (e.g.) a remote NFS mount, you can
open it just like a local file.  Otherwise, you'll need to download it,
whatever you want to call the process.  Common access methods include FTP
and HTTP.

: I have tried:
: 
: @DataFile = ();
: $FileName = "http://www.somesite.com/file.dta";
: 
: open (DATAFILE, "<$FileName");

Don't do unchecked opens.

Many people have suggested that open() be further magic-ified to do an
http get transparently when handed something with an http: prefix, but
that hasn't happened yet.  Until then, you most likely want the
LWP::Simple module, available in the libnet module IIRC.

:   chomp (@DataFile = (<DATAFILE>));

The inner parens are unnecessary.

: Can anyone help me here, I don't won't to download the file, only read
: it.

This is a matter of semantics; if it starts off on a remote machine, and
you end up processing it on a local machine, the file got downloaded.
What happens to it afterward is an app-layer issue.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Every force evolves a form."
   |              - Shriekback


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

Date: Tue, 05 Sep 2000 21:55:23 GMT
From: Mark <mtaylorlrim@my-deja.com>
Subject: Re: Input problem
Message-Id: <8p3q43$hlc$1@nnrp1.deja.com>

In article <8p3k6l$apf$1@nnrp1.deja.com>,
  marxjkj123@my-deja.com wrote:
> Hello all,  I have a bit of a problem.  I'm trying to pass a variable
> from one form(form_X) to another perl script(script_Y).
>
> For example, here is line in form_X
> print       "<FORM name=ias METHOD='POST' ACTION=./HTML.pl -
variable>";
>
> "-variable" should be the input variable to HTML.pl.  I tried using
> @ARGV, but no success.  All it returned where zeros.
>

print "<form action=\"http://yourcgiscript\" method=\"post\">\n";
print "<input type=\"hidden\" name="var name" value=\"var value\">\n";
 ...
print "<input type=\"submit\" value=\"Submit\">\n";   # the button


try this...

Mark


--
Please reply to this newsgroup as my Deja mail
is used as a spam catcher only!


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 05 Sep 2000 23:03:14 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Input problem
Message-Id: <SYet5.28219$C5.585449@typhoon.austin.rr.com>

In article <8p3q43$hlc$1@nnrp1.deja.com>,
Mark  <mtaylorlrim@my-deja.com> wrote:

>print "<form action=\"http://yourcgiscript\" method=\"post\">\n";
>print "<input type=\"hidden\" name="var name" value=\"var value\">\n";
                                    ^        ^
Those would need to be escaped with backslashes for this to work.

If you really don't want to use some module (CGI.pm, maybe) then you could
at least select quotes which reduce the number of \s you need e.g.

  print qq{<input type="hidden" name="var name" value="var value">\n};

The perlop man page describes this under Quote and Quote-like Operators.

Or you could use a "here doc"

print <<END_OF_HTML ;
 ...
<input type="hidden" name="var name" value="var value">
 ...
END_OF_HTML

>...
>print "<input type=\"submit\" value=\"Submit\">\n";   # the button

Just a thought,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |
GPG PGP Key 1024D/059913DA         | Fingerprint      0570 71CD 6790 7C28 3D60
stok@colltech.com (CT - work)      |                  75D2 9EC4 C1C0 0599 13DA


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

Date: Tue, 05 Sep 2000 22:25:38 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: intranet using perl cgi
Message-Id: <89sars88fgq52atb8usi743qso7m814tpi@4ax.com>

richard_dobson@my-deja.com wrote:

>Please could someone give me some ideas? I have to come up with some
>good ideas for a research companies intranet. They would like it to
>become a vital information resource for the workers, and an invaluable
>forum for information interchange. All I can think of really is using
>a bulletin board or chatgroup/newsgroup kind of setup.

There's a book available at O'Reilly's: "Practical Internet Groupware",
by Jon Udell (former Byte contributor). I think it's this kind of ideas
you're looking for.

	<http://www.oreilly.com/catalog/pracintgr/>


Too bad that the sample chapters aren't about the technical stuff --
plenty of that in the book.

-- 
	Bart.


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

Date: Tue, 5 Sep 2000 15:57:08 -0700
From: "Joe Thomas" <jthomas@woodland.org>
Subject: Re: IPC::Shareable "Munged shared memory segment" errors
Message-Id: <sraugc6bljn162@news.supernews.com>

"steven" <steven@ircnet.dk> wrote in message
news:8p2kpk$8uk$1@nnrp1.deja.com...

> > I'm using IPC::Shareable 0.51 under Perl 5.6.0 and mod_perl 1.24 on
> > Linux 2.0.36, I have a shared hash which is created and accessed fine
> > until I delete() a hash element.
>
> Ok after more playing I thought I'd copy the tied hash to a temporary
> hash, make the changes there and copy the hash back. I lock the tie
> using the method in the pod and issue a normal:
>
> %hash = %temp;
>
> Yet the element I deleted still appears in the original tied hash. Is
> there a problem with deleting elements from tied hashes with
> IPC::Shareable under mod_perl? I'm starting to think it may be a
> variable scope and/or lifetime thing, but I'm still stumped as to how to
> solve this.

I've had no luck at all sharing hashes with IPC::Shareable.  When I insert
or delete to a hash in one process, the change isn't seen in other processes
that are sharing the hash.  When I posted about this last week (with code
showing the problem, reproduced here), I saw no responses.  Are you at least
getting farther than I am?

Thanks,
Joe

Here's my test script:

#!/usr/bin/perl -w
use strict;
use IPC::Shareable;

use vars qw($counter %hash);
tie %hash, 'IPC::Shareable', undef, {create => 'yes', destroy => 'yes'};
tie $counter, 'IPC::Shareable', undef, {create => 'yes', destroy => 'yes'};

$| = 1;

for (my $i = 0; $i < 3; $i++) {
 sleep 1;
 next if fork();
 hashcount(3, 3);
 exit;
}

while (1) {
 last if wait() == -1;
}

sub hashcount {
 my ($loops, $sleeptime) = @_;
 for (my $i = 0; $i < $loops; $i++) {
  (tied $counter)->shlock;
  (tied %hash)->shlock;
  $hash{++$counter} = $$;

  print "Process $$ sees:\n";
  for my $key (sort keys %hash) {
   print "\$hash{$key} = $hash{$key}\n";
  }
  (tied %hash)->shunlock;
  (tied $counter)->shunlock;
  sleep $sleeptime;
 }
}

exit;



The results I get:

[jthomas@server ~]$ ./ipctest.pl
Process 3737 sees:
$hash{1} = 3737
Process 3738 sees:
$hash{2} = 3738
Process 3739 sees:
$hash{3} = 3739
Process 3737 sees:
$hash{1} = 3737
$hash{4} = 3737
Process 3738 sees:
$hash{2} = 3738
$hash{5} = 3738
Process 3739 sees:
$hash{3} = 3739
$hash{6} = 3739
Process 3737 sees:
$hash{1} = 3737
$hash{4} = 3737
$hash{7} = 3737
Process 3738 sees:
$hash{2} = 3738
$hash{5} = 3738
$hash{8} = 3738
Process 3739 sees:
$hash{3} = 3739
$hash{6} = 3739
$hash{9} = 3739





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

Date: Wed, 6 Sep 2000 01:20:25 +0200
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Monitoring a network
Message-Id: <1egijo9.oajwqi1yp6oyxN%tony@svanstrom.com>

Willy Wally <paolo.ercy@tin.it> wrote:

> I'm writing a perl cgi for pinging hosts and checking unix daemons without
> using the "ps" unix command. Does anyone know if (and where) i can find
> something for doing this in perl??

How about CPAN...?!? :)


     /Tony
-- 
     /\___/\ Who would you like to read your messages today? /\___/\
     \_@ @_/  Protect your privacy:  <http://www.pgpi.com/>  \_@ @_/
 --oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
   on the verge of frenzy - i think my mask of sanity is about to slip
 ---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
    \O/   \O/  ©99-00 <http://www.svanstrom.com/?ref=news>  \O/   \O/


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

Date: 6 Sep 2000 01:02:17 GMT
From: homer.simpson@springfield.nul (Homer Simpson)
Subject: Re: Monitoring a network
Message-Id: <8p452p$1os$0@216.39.131.170>

In article <8p3opo$i9c$1@pegasus.tiscalinet.it>, "Willy Wally" <paolo.ercy@tin.it> wrote:
>I'm writing a perl cgi for pinging hosts and checking unix daemons without
>using the "ps" unix command. Does anyone know if (and where) i can find
>something for doing this in perl??

Well if you're not too cheap O'Reilly has just release a new volume devoted to 
using Perl for sysadmin tasks on Mac/Win/Unix platforms.  $35.00 for over 400 
pages.
        (It's next on my list after a finish with Perl on Win32 systems)

And FREEBEEs:
The website lists details, a sample chapter to read and a download of all the 
code examples.

You can't go wrong with O'Reilly...

http://www.oreilly.com/catalog/perlsysadm/


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

Date: Tue, 5 Sep 2000 23:01:32 +0100
From: "Tom Fotheringham" <tom@webign.co.uk>
Subject: My Perl got better. So I made this
Message-Id: <8p3qg4$ev0$1@plutonium.btinternet.com>

http://server2038.virtualave.net/tomfoth/theone.pl




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

Date: Wed, 06 Sep 2000 00:42:13 +0200
From: Sven Rixen <post@svenrixen.de>
Subject: Pattern matching
Message-Id: <39B576C5.E471777E@svenrixen.de>

Hello

I've got a little problem with a matching operation.

In a script I use the term

if(${$searchfield1} =~ /$search_for1/){

The problem is now, that if you type just one letter - let's say an 's'
the script will return the first datarow it encounters where the
searched word begins with an 's'.

How can I force the script to compare the complete words and not just
stop after it finds a partial match?

Kind regards
Sven Rixen

_______________________________________________

RIXEN.NET
Webdesign - Sitemanagement - Webprogrammierung

Sven Rixen
mailto:sven@rixen.net

Telefon: +49 (0)521 17 82 43
Mobil:   +49 (0)179 21 73 542

http://www.rixen.net




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

Date: Tue, 05 Sep 2000 19:02:03 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: Pattern matching
Message-Id: <39B57B6A.36D60F46@cc.gatech.edu>

Sven Rixen wrote:

> Hello
>
> I've got a little problem with a matching operation.
>
> In a script I use the term
>
> if(${$searchfield1} =~ /$search_for1/){
>
> The problem is now, that if you type just one letter - let's say an 's'
> the script will return the first datarow it encounters where the
> searched word begins with an 's'.
>
> How can I force the script to compare the complete words and not just
> stop after it finds a partial match?

Use ^ to match the beginning of the string, and $ to match the end.
It sounds like you need the regex to be /^$search_for1$/
perldoc perlre

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




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

Date: Tue, 05 Sep 2000 22:14:41 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Stable sorting
Message-Id: <h0sars8ipd6fdcp295q8u3q61skkg4q1oe@4ax.com>

Uri Guttman wrote:

>  BL> 	@sorted = map { $_->[1] }
>  BL> 	  sort { $a->[1][3] <=> $b->[1][3] || $a->[0] <=> $b->[0] }
>  BL> 	    map { [ $_, $records[$_]] } @records;
>
>you can't tell that is stable unless you define what is in @records. 

Argh! Replace that last @records with  0 .. $#records

The final thing to sort to is the original array index.

-- 
	Bart.


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

Date: 05 Sep 2000 15:38:34 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Stable sorting
Message-Id: <m1lmx6o45x.fsf@halfdome.holdit.com>

>>>>> "Uri" == Uri Guttman <uri@sysarch.com> writes:

Uri> but the GRT is faster

The GRT is faster for those items that can be serialized in a
reasonable amount of time, without a loss of precision, and keys that
can be packed into a fixed data size mapping into a sortable string,
leaving the original data at the trail of the keys.  I suppose you
could count "Storable" as a reasonable serializer, but it's still just
a subset of the sorting problems of the world.

Yeah, I suspect you meant "the GRT is faster" for this particular
example, but I didn't want people to think the GRT can universally
replace the ST, in either speed or power.  Both are valid members of
your toolkit.

For example, the GRT cannot sort "strings of arbitrary length, case
insensitive", a fairly common requirement.  You have to define an
upper bound for the length of a string.  Whereas this is trivial with
an ST.

Unless I misunderstand the entire subtleties of the GRT.

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


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

Date: 05 Sep 2000 16:00:20 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Stable sorting
Message-Id: <m1aedmo35n.fsf@halfdome.holdit.com>

>>>>> "Randal" == Randal L Schwartz <merlyn@stonehenge.com> writes:

Randal> For example, the GRT cannot sort "strings of arbitrary length, case
Randal> insensitive", a fairly common requirement.  You have to define an
Randal> upper bound for the length of a string.  Whereas this is trivial with
Randal> an ST.

Randal> Unless I misunderstand the entire subtleties of the GRT.

And after rereading the paper, I'm more convinced of this.  If you
restrict your input data to "strings that don't contain NULs", or
"strings that do not exceed X chars", you can do it with GRT.  But a
general solution cannot use the GRT, hence back to the ST or (gasp!)
the original sorting.

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


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

Date: Tue, 05 Sep 2000 22:04:07 GMT
From: smehta60@my-deja.com
Subject: string parsing/pattern matching
Message-Id: <8p3qkd$i81$1@nnrp1.deja.com>

Hello all:

I have the following pseudo code:

if ($OS eq "windows")
   $fileSeperator = "\\";
else
   $fileSeperator = "/";

I have a file name that is:
$fname=$startDir.$fileSeperator."temp".$fileSeperator."temp2".$fileSeper
ator;

So for e.g. on a windows m/c I have a file name that is :
$fname=c:\mystartdir\temp\temp2\;

I need to parse the above string so that I have a new string that has
only the word temp2 (i.e the subtsring between the last and the 2nd
last fileseperator).

Is there anyway that I can do this.

TIA

smehta60


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 6 Sep 2000 02:14:32 +0100
From: "Michael Kiwaczinski" <kiwi@kiwinet.de>
Subject: UDP Broadcast does not work
Message-Id: <8p4289$q9d$12$1@news.t-online.com>

Hi,

$host="192.168.0.1" will work, but a Broadcast didn`t (255.255.255.255) --
WHY? I have SuSe 6.4 (Kernel 2.2.14). And i testet it under root

#!/usr/bin/perl -w
#use strict;
use Socket;
use Fcntl;
use Sys::Hostname;

$toport = 9009;
$fromport = 9010;
$tohost = "255.255.255.255";
$message = "Hallo Welt";
$bindhost = "0.0.0.0";

socket(S, AF_INET, SOCK_DGRAM, getprotobyname('udp'));
setsockopt(S, SOL_SOCKET, SO_BROADCAST, pack("l", 1));

$iaddr = gethostbyname($bindhost);
$paddr = sockaddr_in($fromport, $iaddr);
bind(S, $paddr);

$hisiaddr = inet_aton($tohost);
$hispaddr = sockaddr_in($toport, $hisiaddr);
send S, $message, 0, $hispaddr;



--
"It's not easy being green" (Kermit the frog)
Mulzergraben12, 87700 Memmingen
Telefon: +49 8331 490275







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

Date: Wed, 6 Sep 2000 00:13:33 +0100
From: Mark Worsdall <linux@wizdom.org.uk>
Subject: uninitialized value - but I have initilised it! Haven't I?
Message-Id: <16yhpIAd4Xt5EwA6@worsdall.demon.co.uk>

Why do I get this error:-

Use of uninitialized value at /usr/www/cgi-bin/DisplayAgents.pl line 57.

Line 57: @pairs = split(/&/, $ENV{'QUERY_STRING'});


from this code:-

my $name   = '';
my $value  = '';
my $pair   = '';
my @pairs  = ();
my $buffer = '';

    if ($ENV{'REQUEST_METHOD'} eq 'GET') {
        # Split the name-value pairs
        @pairs = split(/&/, $ENV{'QUERY_STRING'});
    }
    elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
        # Get the input
        read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
 
        # Split the name-value pairs
        @pairs = split(/&/, $buffer);
    }
    else {
        exit;
    }


-- 
He came from Econet - Oh no, I've run out of underpants :(
Home:- jaydee@wizdom.org.uk       http://www.wizdom.org.uk
Shadow:- webmaster@shadow.org.uk  http://www.shadow.org.uk
Work:- netman@hinwick.demon.co.uk http://www.hinwick.demon.co.uk
Web site Monitoring:-             http://www.shadow.org.uk/SiteSight/


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

Date: Tue, 05 Sep 2000 22:49:51 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: use strict: why?
Message-Id: <jMet5.12243$a5.177428@news1.rdc1.mb.home.com>

In article <slrn8raooo.2hb.hlawson@localhost.localdomain>,
 Hugh Lawson <hlawson@triad.rr.com> wrote:
> This is prob a dumb question, but it's the question I have.
> 
> script follows:
> 
> #!/usr/bin/perl -w
> use strict;
> use Tk;
> use vars qw($mw);
> $mw = MainWindow->new;
> $main::text = "hello";
> #^^^^^^^^^
[snip]

> But, if I change '$main::text' throughout to '$a::text', the program seems
> to work ok, considering it only displays the widget.
> 
> Is there a rule or convention governing this issue? I have searched for
> this without success.

The strict pragma means you must use lexical variables declared 
with my(), package globals declared with 'use vars', or fully
qualified package names for you variables -- $a::text is a fully
qualified package name (the scalar $text in package a::). The strict
pragma does not require you to explicitly declare packages before
creating/using fully qualified package variables. This snippet
might explain it better:

#!/usr/bin/perl -w
use strict;

$main::text = 'sometext';  # scalar $text in package main::
$a::text = 'other text';   # scalar $text in package a::

print "$main::text and $a::text\n";

no strict; # turn it off so we use $text unqualified

package a;        # now we are inside package a::
print "\$text is '$text' in package a::\n";

package main;     # back in package main::
print "\$text is '$text' in package main::\n";
__END__

regards,
andrew

-- 
Andrew L. Johnson   http://members.home.net/perl-epwp/
      There ain't nothin' in this world that's worth being a snot over.
          -- Larry Wall in <1992Aug19.041614.6963@netlabs.com>


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

Date: Tue, 05 Sep 2000 22:18:32 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: using perl in a redundant way.
Message-Id: <8p3rf9$j8c$1@nnrp1.deja.com>

In article <8p3nv5$f82$1@nnrp1.deja.com>,
  johnvert@my-deja.com wrote:
> Hello,
>
> Recently there was talk here about how some people write Perl like
they
> write C, and someone (I believe Uri) suggested to post code here, so
> that someone can guide me to the Perlish way.  Well, I'm one of these
> people -- I write Perl like I write C, and I would like you to tear
this
> piece of code apart.  Don't be nice:
>
> # this segment italicizes comments in various programming languages.
> # there must be a better way.
> while(defined($line=<SRC>))

couls use the scratch pad variable $_, reducing the statement to

while (<SRC>)  {


> {
>     # C
>     if($line=~m|/\*|){
>         $line=~s|/\*|\<i\>/\*|;
>     }
>     if($line=~m|\*/|){
>         $line=~s|\*/|\*/\</i\>|;
>     }

no need to 'search' before replace
s#/\*#<i>/\*#;
s#\*/#\*/</i>#;

>
>     # C++
>     if($line=~m|//|){
>         $line=~s|//|\<i\>//|;
>         $line=~s|\n|\</i\>\n|;
>     }

could use:
s#(//.*)#<i>$1</i>#;


>
>     # Scheme
>     if ($line=~m|;;|) {
>         $line=~s|;;|\<i\>;;|;
>         $line=~s|\n|\</i\>\n|;
>     }

what if the source file was a C file and you had a for(;;) loop?

>
>     print $line;
> }

using the $_ that would become print();

I know I'll probably get shot for this, but I hate list syntax....I
admit to having a soft spot for parenthesis.

Brendon
++++



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 05 Sep 2000 22:30:55 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: using perl in a redundant way.
Message-Id: <zuet5.12242$a5.177879@news1.rdc1.mb.home.com>

In article <x77l8qms04.fsf@home.sysarch.com>,
 Uri Guttman <uri@sysarch.com> wrote:

[snip]

> so your code reduces to:
> 
> 
> 	while( $line = <SRC> ) {

wouldn't it be more perlish to do while(<SRC>) and
then operate on $_ ?
 
> 		$line =~ m{/\*}{<i>/*} ;	# C start
> 		$line =~ m{\*/}{*/</i>} ;	# C end
                         ^
that's a funny looking s  uri :-)

> 		$line =~ s{(//.*$)}{<i>$1</i>}	# C++
> 		$line =~ s{(;;.*$)}{<i>$1</i>}	# scheme
> 
> 		print $line ;
> 	}

another reduced version might be:

    while(<SRC> ){
        s{(?:(//.*$|;;.*$)|(/\*)|(\*/))}
         {$1?"<i>$1</i>":$2?"<i>$2":$3?"$3</i>":''}eg;
        print;
    }

but it looks like rain here, so I think I'll just head straight over
to the 19th hole ...

> and that is very broken if any of those strings appear in quoted
> strings, nested comments, etc. 

ditto.

andrew

-- 
Andrew L. Johnson   http://members.home.net/perl-epwp/
      I've always maintained a cordial dislike for indent, because it's
      usually right.
          -- Larry Wall in <199806221558.IAA07251@wall.org>


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

Date: Tue, 05 Sep 2000 22:26:14 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: version problem?
Message-Id: <8p3rtl$jlj$1@nnrp1.deja.com>

In article <39b435e0_1@nntp2.nac.net>,
  "ortius" <asleep@thewheel.com> wrote:
> Hello:
>
> We're writing  some perl scripts.... have a crazy dilemma. Not sure
why. If
> we run the scripts on a free bsd or linux box using perl 5.003, all
is well.
> It makes no difference whether the first line is #!/usr/bin/perl5.003
or
> simply #!/usr/bin/perl . They run fine with chmod 755 on these boxes.
>
> We need to put these same scripts on a va linux box that's set up for
> perl5.005_03. But , they WON't run at all, unless we chmod 777, which
is not
> preferred.Is there something vastly different between these versions?
Some
> other problem somebody can infer from the description I'm giving?
>
> Going bald & losing sleep... yeesh!
>
> mike
> omniNOSPAM@nac.net

as far as I know on the standard red hat distribution,
/usr/bin/perl and /usr/bin/perl5whatever are hard links.

does the system 'complain' in any way?

Brendon
++++



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 5 Sep 2000 19:51:49 -0500
From: "Chris Stith" <mischief@motion.net>
Subject: Re: Win32 Registry and IP addresses.
Message-Id: <srb56sogljn130@corp.supernews.com>


<psb154@my-deja.com> wrote in message news:8o5p3c$djv$1@nnrp1.deja.com...
> Idiot!
>
> In article <39A650D6.7CEC9D5F@patriot.net>,
>   H C <carvdawg@patriot.net> wrote:
>
> > > Have not thought this through too much so any suggestions would be
> great.
>
> > I don't mean any offense, but it's pretty obvious that you haven't
> put any
> > thought into
> > this.
>
> > Most of the info you want to add to the Registry is located in:
> >
> > HKLM\System\CurrentControlSet\Services\[device]\Parameters\Tcpip
> >
> > Some is in:
>
> This should be: "Some are in"

Incorrect correction. The subject is 'the info'. The word 'info', or
'information' in the full form, is what might be referred to as a collective
singular. Kind of like 'the band is touring' / 'the band members are
touring' or 'the flock is flying south' / 'the birds of the flock are flying
south'. The poster was referring to info as a block of related info.
There is a vague notion here that suggests that although 'info' is mentioned
in the singular (as it invariably is) that it should be a special case
because
it's thought of as being in more than one place, so there must be an implied
'certain members of' attached. It would be a good idea, grammatically, to
include such a phrase in the subject and then change the conjugation of the
verb. This is, however, not necessary according to informal American usage
of the English language.

> >
> > HKLM\System\CurrentControlSet\Services\TCPIP\Parameters
> >
> > I find Win32::TieRegistry by far the easiest module to use with the
> > Registry...
>
> This is NOT where they are located on my computer dude! HKLM\System yes
> but the rest of it... you are pretty much clueless.

Different Win32 systems store things in different parts of the registry. I'm
not sure
if off the top of my head I could remember which keys are for which, but I'm
pretty sure NT and 9x store these settings in two different places.

> I don't mean any offense, but you might want to get a grown up to read
> you messages before you post.

Hey grammar cop, shouldn't that be 'to read your messages before you post'?

> Sent via Deja.com http://www.deja.com/
> Before you buy.





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

Date: Tue, 05 Sep 2000 23:09:12 GMT
From: Chris <exit72@excite.com>
Subject: Re: World Wide PERL PROGRAMMERS TELECOMMUTE
Message-Id: <nguarsg7iupo5f7cj5osgahv740ob2ttcq@4ax.com>

No offense Guttman but if I had to pick on who I didn't want in the
group it would be you. Take a look at some of your responses to posts
and you'll see why, you are the only person that replies with such
hate towards everything.

Soo back in your face for all the newbies you shit on.
      >if you don't get it, you are not wanted here.

Chris



On Tue, 05 Sep 2000 21:34:30 GMT, Uri Guttman <uri@sysarch.com> wrote:

>>>>>> "G" == Godzilla!  <godzilla@stomp.stomp.tokyo> writes:
>
>  >> go hire moronzilla. most money she will ever make. and pay her 
>  >> at the bottom of your scale. you won't be getting your money's
>  >> worth even then.
>
>  G> As you know, Mr. Buttman, at age forty and some odd months,
>  G> I am retired. I have no need for employment. As it is, between
>  G> my twenty year old daughter and myself, our net liquidable
>  G> worth, this year, is one point four million dollars.
>
>so why are you here instead of being a typical rich bitch somewhere
>else? if you don't get it, you are not wanted here.
>
>  G> How are you doing financially?
>
>just fine, thanx for asking.
>
>uri



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

Date: Tue, 05 Sep 2000 23:45:07 GMT
From: mag@ionet.net (Maggert)
Subject: Re: World Wide PERL PROGRAMMERS TELECOMMUTE
Message-Id: <39b58510.949281684@news.ionet.net>

On Tue, 05 Sep 2000 17:35:51 GMT, Uri Guttman <uri@sysarch.com> wrote:

>>>>>> "P" == PERLWorldWidel  <PERLWorldWidel@GLOBALTelecommute.com> writes:
>
>  P> $15.00 to $25.00 per hour commensurate with experience.
>
>HAHAHAHAHHAHAHAAHAH!!

	Hey I saw an add for perl programmers for a whopping $8 bucks
an hour!!! They did have a TV and several game players like Sega and
Nintendo. And their own office!!! This was also in NYC!!!! 


MP


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

Date: Wed, 6 Sep 2000 03:03:56 +0200
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: World Wide PERL PROGRAMMERS TELECOMMUTE
Message-Id: <1egio76.ivpfcg39gwkN%tony@svanstrom.com>

Chris <exit72@excite.com> wrote:

> No offense Guttman but if I had to pick on who I didn't want in the
> group it would be you. Take a look at some of your responses to posts
> and you'll see why, you are the only person that replies with such
> hate towards everything.

Instead of people that knows what they are doing you want brownnoses
that don't know anything, but are cheap and tell you exactly what you
want to hear? Interesting businessidea, do tell us how it works out...


     /Tony
-- 
     /\___/\ Who would you like to read your messages today? /\___/\
     \_@ @_/  Protect your privacy:  <http://www.pgpi.com/>  \_@ @_/
 --oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
   on the verge of frenzy - i think my mask of sanity is about to slip
 ---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
    \O/   \O/  ©99-00 <http://www.svanstrom.com/?ref=news>  \O/   \O/


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

Date: Wed, 6 Sep 2000 03:03:57 +0200
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: World Wide PERL PROGRAMMERS TELECOMMUTE
Message-Id: <1egio99.7yqzeg1qs1gcgN%tony@svanstrom.com>

Maggert <mag@ionet.net> wrote:

> On Tue, 05 Sep 2000 17:35:51 GMT, Uri Guttman <uri@sysarch.com> wrote:
> 
> >>>>>> "P" == PERLWorldWidel  <PERLWorldWidel@GLOBALTelecommute.com> writes:
> >
> >  P> $15.00 to $25.00 per hour commensurate with experience.
> >
> >HAHAHAHAHHAHAHAAHAH!!
> 
>       Hey I saw an add for perl programmers for a whopping $8 bucks
> an hour!!! They did have a TV and several game players like Sega and
> Nintendo. And their own office!!! This was also in NYC!!!! 

Well, if they have cable... ;-)


Seriously though, personally I could work for food and somewhere to
sleep (for shorter projects, and if I know/like the person on the Net
already) just to have fun, see a new part of the world and meet new
people... Money isn't everything in life. :-)


     /Tony
-- 
     /\___/\ Who would you like to read your messages today? /\___/\
     \_@ @_/  Protect your privacy:  <http://www.pgpi.com/>  \_@ @_/
 --oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
   on the verge of frenzy - i think my mask of sanity is about to slip
 ---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
    \O/   \O/  ©99-00 <http://www.svanstrom.com/?ref=news>  \O/   \O/


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

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 V9 Issue 4230
**************************************


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