[17659] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5079 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 11 03:05:33 2000

Date: Mon, 11 Dec 2000 00:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <976521908-v9-i5079@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 11 Dec 2000     Volume: 9 Number: 5079

Today's topics:
    Re: %ENV does not contain some variables? (Richard Zilavec)
    Re: Adding a Bcc recipient? <mikecook@cigarpool.com>
    Re: Date Manipulation / Cron Job <mikecook@cigarpool.com>
    Re: DBM File Open Problem (Richard Zilavec)
        File limit to save on HDD bakha_ma@my-deja.com
    Re: File limit to save on HDD (Jens)
    Re: Formating file in Win-Perl bakha_ma@my-deja.com
    Re: Getting properties of a word-file with Win::32OLE sraheja@my-deja.com
    Re: How do I find out my own IP Address? (James Kufrovich)
    Re: need help with split <monty@primenet.com>
    Re: Performance optimization of DBI::CSV <jeff@vpservices.com>
    Re: Perl Help with LWP (Rafael Garcia-Suarez)
        Problem understanding references <peter.sundstrom@eds.com>
    Re: Problem understanding references (Richard Zilavec)
    Re: Problem understanding references <uri@sysarch.com>
    Re: Problem understanding references (Rafael Garcia-Suarez)
        There must be a better way <akent6036@my-deja.com>
    Re: There must be a better way <jeffp@crusoe.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 11 Dec 2000 06:12:00 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: %ENV does not contain some variables?
Message-Id: <3a346fd1.267839190@news.tcn.net>

On Mon, 11 Dec 2000 01:00:55 GMT, "John W. Krahn" <krahnj@acm.org>
wrote:

>First off, I searched through the FAQs and perldoc. Here it is in a
>nutshell:
>
>$ echo "Columns = $COLUMNS    Lines = $LINES "
>Columns = 130    Lines = 43 
>$ perl -e 'print "Columns = $ENV{COLUMNS}    Lines = $ENV{LINES} \n";'
>Columns =     Lines =  

COLS=10; export COLS

echo $COLS

This works for me using bash.


--
 Richard Zilavec
 rzilavec@tcn.net


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

Date: Sun, 10 Dec 2000 23:29:46 -0700
From: "Michael Cook" <mikecook@cigarpool.com>
Subject: Re: Adding a Bcc recipient?
Message-Id: <mx_Y5.5565$0p4.574302@news.uswest.net>

"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn938b68.nr.mgjv@verbruggen.comdyn.com.au...
> On Wed, 6 Dec 2000 21:56:08 -0700,
> Michael Cook <mikecook@cigarpool.com> wrote:

> Your post contained many bad things. Whether or not you would fix
> these in your production code is beside the point. You presented code,
> so you should not be surprised when others criticise it, especially if
> you know (and you claim you do) that it contains potential nasty
> surprises for the less experienced cut-and-paster.
>
> Martien
> --
> Martien Verbruggen              |
> Interactive Media Division      | If it isn't broken, it doesn't have
> Commercial Dynamics Pty. Ltd.   | enough features yet.
> NSW, Australia                  |


Point well taken - the next time I post snippets, I will explain possible
gotchas.
<RANT>
BTW, I am not surprised it was criticized - the point here was that someone
asked a question & received no help - my code snippet should have been more
complete, but it helped the original poster and I was the only one that
offered anything other than high-handed, patronizing responses. I also wrote
that I would be happy to help further and please email for more details. I
never claimed to be an expert with perfect code, but the code I have written
does work and has been researched extensively. I would *love* to have
someone go over my code and (constructively) point out where I could improve
it, but do not have those resources available.
If you were a beginner and were stuck, would you rather have someone give
you some code that works (albeit incomplete) or would you rather be told to
buzz off? I was very frustrated in the beginning & got the brush off from
many who had the ability to help and took the time to put me down instead
(which took longer than helping would have in many cases). Sometimes I feel
that this is an elitist, self-serving club in many aspects rather than a
community (but I really enjoy programming {not my line of work}and helping
others when I can).
</RANT>
    Michael
--
== CigarPool ==
http://www.cigarpool.com





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

Date: Sun, 10 Dec 2000 23:15:20 -0700
From: "Michael Cook" <mikecook@cigarpool.com>
Subject: Re: Date Manipulation / Cron Job
Message-Id: <2k_Y5.5467$0p4.567378@news.uswest.net>

Have the Perl script run every week. Have it test for the existence of a
control file (call it something like DO_NOT_DELETE). If it exists, delete it
and run your commands. If it does not exist, create it and exit.
    Michael
--
== CigarPool ==
http://www.cigarpool.com

"Mark Henderson" <markh@argolink.net> wrote in message
news:3A33B46C.1C913CE9@argolink.net...
> Greetings:
>
> I don't have the ability to instal new modules on my ISP's server
> (running Perl 5.05), and they are a bit sticky about such things.  So, I
> was wondering if any of you might be able to help me with a code
> snippet.   The problem is as follows:
>
> 1)  I want to execute a function to clean up my database every other
> Monday.  I can easily have my ISP institute a cron job on the server to
> kick of my Perl script that cleans the database, but the problem with
> cron is that it can only be told to run every Monday.
>
> 2)  When my Perl script executes every Monday, I want to have some code
> in it to check and see if this is an even or odd Monday and either exit
> or perform the functions for cleaning the database.  Does anybody have
> any code snippets or references for how I might check the date, and then
> determine if this is the Monday that I want to execute the database
> cleaning functions?
>
> Replies off-list are also welcome.
>
> Thanks,
>
> Mark
>




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

Date: Mon, 11 Dec 2000 06:27:23 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: DBM File Open Problem
Message-Id: <3a34737c.268778470@news.tcn.net>

On Sun, 10 Dec 2000 12:48:05 -0800, "Steve Bobrowski"
<sbobrows@ix.netcom.com> wrote:


>library, but still cannot access the existing DBM files (or restored backups
>of the files).

What is the error message in the logs?  I bet you have, but just
incase, have you checked the owership and permissions of the files?


--
 Richard Zilavec
 rzilavec@tcn.net


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

Date: Mon, 11 Dec 2000 05:47:01 GMT
From: bakha_ma@my-deja.com
Subject: File limit to save on HDD
Message-Id: <911pok$jm6$1@nnrp1.deja.com>

Hello everyone!

I have a very newbie question for you all!  I am working on developing
a Perl script to run as a cgi-bin script on a web server under Windows
98 and am having a problem.  When I try to save text from a web form,
it appears that only 1.5Kb of text is getting saved.  I paste in 4Kb of
information, but only 1.5Kb make it to the file.  Here is the script
itself:
#!c:\perl\bin\perl
# savef.pl
#Function to decoding data from HTTP
sub urldecode {
	local($val)	= @_;
	$val =~ s/\+/ /g;
	$val =~ s/%([0-9a-hA-H]{2})/pack('C',hex($1))/ge;
	return $val;
}


#Get parametrs from query-string
if ($ENV{'REQUEST_METHOD'} eq 'GET'){$query = $ENV{'QUERY_STRING'};}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST')
  {sysread(STDIN, $query, $ENV{'CONTENT_LENGTH'});}
  if ($query ne '') {
  	@formfields = split(/&/,$query);
  	foreach (@formfields) {
  	 if (/^ffile=(.*)/){$ffile=urldecode($1);}
  	 if (/^txtview=(.*)/){$txtview=urldecode($1);}
     }
   }


#Save file to HDD
open(PASS, ">$ffile") || die "Not works! $!";
while ( $txtview =~ s/\n// ) {
 chomp($txtview);
}
print PASS "$txtview";
close (PASS);


Thanks in advance for any help you can provide!

Bakha


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


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

Date: Mon, 11 Dec 2000 08:03:59 +0100
From: "Ellegiers, J. M. (Jens)" <jellegie@ford.com>
Subject: Re: File limit to save on HDD
Message-Id: <3A347C5F.1262102C@ford.com>

Hi,

make sure that you use 'post' as method for your form. In
'get'-requests, the amount of data passed is restricted to - IIRC 2048
Bytes. This limit does not exist for 'post'ed data.

Regards

Jens

bakha_ma@my-deja.com wrote:
> 
> Hello everyone!
> 
> I have a very newbie question for you all!  I am working on developing
> a Perl script to run as a cgi-bin script on a web server under Windows
> 98 and am having a problem.  When I try to save text from a web form,
> it appears that only 1.5Kb of text is getting saved.  I paste in 4Kb of
> information, but only 1.5Kb make it to the file.  Here is the script
> itself:
> #!c:\perl\bin\perl
> # savef.pl
> #Function to decoding data from HTTP
> sub urldecode {
>         local($val)     = @_;
>         $val =~ s/\+/ /g;
>         $val =~ s/%([0-9a-hA-H]{2})/pack('C',hex($1))/ge;
>         return $val;
> }
> 
> #Get parametrs from query-string
> if ($ENV{'REQUEST_METHOD'} eq 'GET'){$query = $ENV{'QUERY_STRING'};}
> elsif ($ENV{'REQUEST_METHOD'} eq 'POST')
>   {sysread(STDIN, $query, $ENV{'CONTENT_LENGTH'});}
>   if ($query ne '') {
>         @formfields = split(/&/,$query);
>         foreach (@formfields) {
>          if (/^ffile=(.*)/){$ffile=urldecode($1);}
>          if (/^txtview=(.*)/){$txtview=urldecode($1);}
>      }
>    }
> 
> #Save file to HDD
> open(PASS, ">$ffile") || die "Not works! $!";
> while ( $txtview =~ s/\n// ) {
>  chomp($txtview);
> }
> print PASS "$txtview";
> close (PASS);
> 
> Thanks in advance for any help you can provide!
> 
> Bakha
> 
> Sent via Deja.com http://www.deja.com/
> Before you buy.

-- 
Viele Gruesse, regards, saludos
Jens Ellegiers
---------------------------------------------------------------
FORD-Werke AG, Spessartstrasse, 50725 Koeln
Jens Ellegiers                         Email: jellegie@ford.com  /"\
Engineer (I-Engine CAE)                Phone: +49-221-90-31467   \ /
Mail Sym: D-ME/PN-S                    Fax  : +49-221-90-33025    X
ASCII Ribbon campaign against HTML E-mail & Usenet News >------> / \


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

Date: Mon, 11 Dec 2000 05:37:31 GMT
From: bakha_ma@my-deja.com
Subject: Re: Formating file in Win-Perl
Message-Id: <911p6r$j94$1@nnrp1.deja.com>

In article <3A24EC51.4DF95809@patriot.net>,
  H C <carvdawg@patriot.net> wrote:

Thank you for advise.
Mary Christmas everybody!!!
> Go into the CGI script and remove the extra "\n"


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


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

Date: Mon, 11 Dec 2000 05:22:50 GMT
From: sraheja@my-deja.com
Subject: Re: Getting properties of a word-file with Win::32OLE
Message-Id: <911ob7$io3$1@nnrp1.deja.com>

Try setting $Win32::OLE::Warn = 0; to keep the program running.

See
http://velocity.activestate.com/docs/ActivePerl/site/lib/Win32/OLE/TPJ.html,
which says

"The value of $Win32::OLE::Warn determines what happens when an OLE error
occurs. If it's 0, the error is ignored. If it's 2, or if it's 1 and the
script is running under -w, the in32::OLE module invokes Carp::carp(). If
$Win32::OLE::Warn is set to 3, Carp::croak() is invoked and the program dies
immediately."

Also, add the following to your code:
use Win32::OLE::Const 'Microsoft Word';

Then the following line
Documents.Open FileName:="C:\MyFiles\MyDoc.doc", ReadOnly:=True

in visual basic translates to the perl
$document->Documents->Open({
FileName =>   "C:\MyFiles\MyDoc.doc"
ReadOnly => 1,
});

In article <3A26AF7D.37A8F26B@win.be>,
  gauthier-vdm@ibelgique.com wrote:
> Hello,
>
> I've done a little script that "walks" through a tree of directories and
> creates in each an HTML-file giving a summary of certain types of files
> within. So, with a browser, you can navigate and get some information
> about the files ; this is extracted from <title> and <meta-tags> of the
> HTML-files, from "{\info }" strings of the RTF, same with PDF where you
> have strings like "/Producer (GNU Ghostscript 4.03)" and so.  But this
> script was initially used on a linux-box for the maintenance of a
> website, and now I try to adapt it at work on Windows-NT, where most of
> files are microsoft-doc.
>
> But I don't know *anything* about this system, VisualBasic, OLE...
>
> With some research in archives of forums and Visual Basic-help, I've
> produced this ugly little piece of code, and it works in most of cases.
>
>
######################################################################
#
###########
> ##
>
> $application=Win32::OLE->new('Word.Application');
> # (foreach $file_doc)
> $document=$application->Documents->Open("$file_doc");
>
> $title=$document->BuiltinDocumentProperties->Title->{"Value"};
> $subject=$document->BuiltinDocumentProperties->Subject->{"Value"};
> $author=$document->BuiltinDocumentProperties->Author->{"Value"};
> $keywords=$document->BuiltinDocumentProperties->Keywords->{"Value"};
> $comments=$document->BuiltinDocumentProperties->Comments->{"Value"};
> $date_cre=$document->BuiltinDocumentProperties->{"Creation
> Date"}->{"Value"};
>
> $document=$application->Documents->Close;
> # and so...
> $application->Quit;
>
>
######################################################################
#
###########
> #
> But I'm disappointed to see that when it encounters an error with a
> particular file, the whole script dies !
> By ex. :
> OLE exception from "Microsoft Word":
>
> Win32::OLE(0.1101) error 0x800a1066
>     in METHOD/PROPERTYGET "Open" at H:\UTIL\Index_repertoires.pl line
> 122
> Can't call method "BuiltinDocumentProperties" on an undefined value at
> H:\UTIL\I
> ndex_repertoires.pl line 123, <FICHIER_HTML> chunk 19.
>
> Win32::OLE(0.1101) error 0x8001010a: "The message filter indicated that
> the
> application is busy"
>     in METHOD/PROPERTYGET "" at H:\util\Index_repertoires.pl line 122
> Can't use an undefined value as a HASH reference at
> H:\util\Index_repertoires.pl
>  line 122, <FICHIER_HTML> chunk 296.
>
> It could be safer to open the doc-files read-only (in case of somebody
> has all open it) but I don't know how translate the VisualBasic Code :
> Documents.Open FileName:="C:\MyFiles\MyDoc.doc", ReadOnly:=True
> When I try
> $document=$application->Documents->Open("$fichier_doc, ReadOnly:=True
> ");
> the string is of course considered as a whole filename. How add an
> optional "Variant" to a VB-Method, like
> "SaveChanges:=wdDoNotSaveChanges"
> to "Quit" ?
>
> Could someone give me a simple solution to do that, and, more generally,
> to avoid this script dies whenever it meets an "OLE exception from
> "Microsoft Word":" ?
>
> It's not /so/ (!) important if I don't get the information from the
> file,
> but it's important that the script runs continuously without human
> intervention, so Word *can't* open a undesirable window to propose to
> save the file with another name and so...
>
> Thanks by advance,
>
> --
>
>  #=---------------------------------------------------=#
>  "          ^^      Gauthier Vandemoortele             "
>  |   (_____/°°-ç    gauthier-vdm@ibelgique.com         |
>  |   |     \_`-"                                       |
>  |   )/@mmm||       Chée de Wavre, 135c                |
>  |   \nn   \nn      B-1360 Perwez                      |
>  |                  Belgique                           |
>  " FOE-Belgium : http://www.ful.ac.be/hotes/amisterre  "
>  #=---------------------------------------------------=#
>



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


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

Date: Mon, 11 Dec 2000 06:17:01 GMT
From: eggie@REMOVE_TO_REPLYsunlink.net (James Kufrovich)
Subject: Re: How do I find out my own IP Address?
Message-Id: <slrn938sjh.1kv.eggie@melody.mephit.com>

On Fri, 08 Dec 2000 23:51:43 +0100, Christoph <cvh@gmx.de> wrote:
>Hello,
>
>could anybody tell me how to find out the IP-address that my
>internet-provider gives me at dial-up?
>I allready searched CPAN but I couldn't find anything that looks like a
>solution.

IPADDR=`/sbin/ifconfig ppp0 | grep inet | perl -ane '$temp = $F[1]; $ip =
substr($temp,5,100); print $ip, "\n";'`

	I have that in a bash script, and it works fine.  I suppose it can
be done similarly in Perl.  Hope this helps (tm).

Jamie Kufrovich

-- 
Egg, eggie@REMOVE_TO_REPLYsunlink.net
FMSp3a/MS3a A- C D H+ M+ P+++ R+ T W Z+ 
Sp++/p# RLCT a+ cl++ d? e++ f h* i+ j p+ sm+


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

Date: 11 Dec 2000 06:38:38 GMT
From: Jim Monty <monty@primenet.com>
Subject: Re: need help with split
Message-Id: <911spe$2jd$2@nnrp2.phx.gblx.net>

Joe <jmourney@hotmail.com> wrote:
> thank you for those who gave me helpful responses.
> after summarizing all your responses, here's what i
> came up with:
>
> ($id,$callnum,$copies,$lang,$title)=split(/\s+/,$record,5);
>
> and this would handle the records i gave as example.
> i run the script with -w, use strict, and scope all vars with my.
>
> but when the script processes records which are missing one
> or more fields, the split function assigns undef or null to
> the corresponding variables.

How does the split function know which fields are missing and which
variables to assign undef to?

> as you know, it generates some
> warning messages when i try to use these variables.
>
> my question is: should i be concerned with the warning messages?

Yes.

> if so, what must be done?

Read the warnings more carefully.

> other than that, the code works okay.

No it doesn't.

> to explain what i mean, try the above code with the following
> record:
>
> MVCD05                 1,2   SPA   Residencia San Juan de La Penitencia

This record will not provoke a warning.

$ cat films
#!/usr/local/bin/perl -w

use strict;

while (<DATA>) {
    chomp;
    my ($id, $callnum, $copies, $lang, $title) = split ' ', $_, 5;
    print "language is $lang, title is $title\n";
}

__END__
MVCD01      Qa1.B75        1,2,3,4    FRE   Au Revoir les Enfants
MVCD02    Ha4.B32        1,*,2,3    GRK Euripides Medea
MVCD05                 1,2   SPA   Residencia San Juan de La Penitencia
$ ./films
language is FRE, title is Au Revoir les Enfants
language is GRK, title is Euripides Medea
language is Residencia, title is San Juan de La Penitencia
$

Oops!

You have a more difficult text parsing problem than you suspected--
one for which split will not suffice. How good are you at crafting
regular expressions? And how well do you know your input data?

Here's an example of what I'm alluding to, but make no assumptions
about the suitability of THIS regex to your problem:

$ cat films
#!/usr/local/bin/perl -w

use strict;

while (<DATA>) {
    my ($id, $callnum, $copies, $lang, $title) = m{
        ^
        ([A-Z]+\d+)                # id
        \s+
        ([A-Za-z]+\d+\.[A-Z]\d+)?  # callnum (optional)
        \s+
        (\S+)                      # copies
        \s+
        ([A-Z]{3})                 # lang
        \s+
        (\S.*)                     # title
    }x;

    print "language is $lang, title is $title\n";
}

__END__
MVCD01      Qa1.B75        1,2,3,4    FRE   Au Revoir les Enfants
MVCD02    Ha4.B32        1,*,2,3    GRK Euripides Medea
MVCD05                 1,2   SPA   Residencia San Juan de La Penitencia
$ ./films
language is FRE, title is Au Revoir les Enfants
language is GRK, title is Euripides Medea
language is SPA, title is Residencia San Juan de La Penitencia
$

-- 
Jim Monty
monty@primenet.com
Tempe, Arizona USA


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

Date: Sun, 10 Dec 2000 21:06:21 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Performance optimization of DBI::CSV
Message-Id: <3A3460CD.E6A5A2BE@vpservices.com>

upuautiii@my-deja.com wrote:
> 
> Is there a way to make DBI::CSV add new records in a table(flat file) at
> the top of the file instead of bottom?

No, you can not insert them at the top.  But you can use the ORDER BY
clause to put them in any order you want and save a new file in that new
physical order, swapping the filenames with your former database if you
want.  That would have the same effect as inserting them at the top but
would be a bit more file system intensive.

> This would be nice if I have a big table(file), and I want to optimally
> find, say, the latest action a user took on the site. By placing the
> most recent entries at the top, the statement can simply look for the
> first occurence, and return. Is this possible?

It is against all of the principles of SQL database management.  There
should be no necessary relationship between the physical order of the
file and the logical ordering of records.  So whatever you did would be
almost guaranteed to break in some other database environment.  Also,
there is (currently) no LIMIT clause in DBD::CSV so you would end up
preparing and executing a full SELECT and the only time you would save
would be to blast out of the fetch loop ofter the first fetch.  OTOH, if
you are generating a session id anyway you can just keep a file that
always has the most current session id and do a SELECT on that id from
the main database which would do the prepare, execute, and fetch on the
one row.

How large is your file and what kind of time are you expecting to save
with this arrangement?  Depending on the size of the file it may be time
for you to move to a real rdbms system anyway.

-- 
Jeff


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

Date: Mon, 11 Dec 2000 07:25:59 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Perl Help with LWP
Message-Id: <slrn9390e4.lps.rgarciasuarez@rafael.kazibao.net>

Wayne Hayes wrote in comp.lang.perl.misc:
> 
> Web Client Programming        # Good info on browsers, http, sockets, lwp::,
> etc.
> Clinton Wong
> O'Reilly
> ISBN 1-56592-214-x

This book is apparently out of print, but available on the web :

http://www.oreilly.com/openbook/webclient/

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Mon, 11 Dec 2000 17:15:37 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Problem understanding references
Message-Id: <911kdc$f2q$1@hermes.nz.eds.com>

I'm having problems understanding references.  The following script snippet
produces the error:

Can't use string ("192.1.1.1") as a symbol ref while "strict refs" in use at
 ./b line 14, <DATA> chunk 1.

I've looked at perlref, but I'm not really any clearer.  Can someone explain
it to me in plain English?

Also, is there a better approach to what the code below does?  I was looking
at using the FileHandle module, but I'm not really sure if it make the code
any better.

#!/usr/local/bin/perl -w

use strict;

my ($addr,%ip);

while (<DATA>) {
        chomp;

        $addr=$_;

        unless ($ip{$addr}) {
                $ip{$addr}=1;
                open($addr, ">$addr.dat") or die "Can not open $addr.dat
$!\n";
        }

        print $addr "IP $addr\n";
}

__DATA__
192.1.1.1
192.1.1.2
192.1.1.3




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

Date: Mon, 11 Dec 2000 06:46:15 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: Problem understanding references
Message-Id: <3a347798.269830600@news.tcn.net>

On Mon, 11 Dec 2000 17:15:37 +1300, "Peter Sundstrom"
<peter.sundstrom@eds.com> wrote:


>#!/usr/local/bin/perl -w
>

use strict;
no strict 'refs';

This allows your code to execute by allowing symbolic and hard
references.


--
 Richard Zilavec
 rzilavec@tcn.net


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

Date: Mon, 11 Dec 2000 06:50:26 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Problem understanding references
Message-Id: <x7puizjvt8.fsf@home.sysarch.com>

>>>>> "RZ" == Richard Zilavec <rzilavec@tcn.net> writes:

  RZ> On Mon, 11 Dec 2000 17:15:37 +1300, "Peter Sundstrom"
  RZ> <peter.sundstrom@eds.com> wrote:


  >> #!/usr/local/bin/perl -w
  >> 

  RZ> use strict;
  RZ> no strict 'refs';

  RZ> This allows your code to execute by allowing symbolic and hard
  RZ> references.

don't encourage use of symbolic references. they are balck magic and the
OP is not skilled enough to use them.

besides, his code didn't really use them. he was using a dotted quad as
a file handle which is very odd. and that was what caused the symref
error. there is no need for that, you can use Symbol to make new handles
and store them in a hash indexed by the IP.

	open($addr, ">$addr.dat") or die "Can not open $addr.dat

in fact why he opens the file named for the IP makes no sense either as
he only prints the IP into it. maybe he meant to print all the unique
IPs to one file. 

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Mon, 11 Dec 2000 07:54:49 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Problem understanding references
Message-Id: <slrn939246.lps.rgarciasuarez@rafael.kazibao.net>

Peter Sundstrom wrote in comp.lang.perl.misc:
> 
> #!/usr/local/bin/perl -w
> 
> use strict;
> 
> my ($addr,%ip);
> 
> while (<DATA>) {
>         chomp;
> 
>         $addr=$_;
> 
>         unless ($ip{$addr}) {
>                 $ip{$addr}=1;
>                 open($addr, ">$addr.dat") or die "Can not open $addr.dat $!\n";

You're trying to use $addr as a filehandle. Thus Perl understands that
$addr is the name of, or a reference to, a filehandle. But it's a
string, hence the complain (because Perl won't fetch the filehandle
whose name is in $addr under "strict 'refs'"). See, for example,
"perldoc -f print".

Use this code:
  open(ADDR, ">$addr.dat") or die...

>         }
>         print $addr "IP $addr\n";

          print ADDR "IP $addr\n";

And you should close the file:
          close ADDR;

> }
> 
> __DATA__
> 192.1.1.1
> 192.1.1.2
> 192.1.1.3

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Mon, 11 Dec 2000 05:25:14 GMT
From: Ash <akent6036@my-deja.com>
Subject: There must be a better way
Message-Id: <911ofn$iqi$1@nnrp1.deja.com>

I'm very new to Perl and would like to know if there is a better method
for splitting up a line than what I am currently using.

I have written a small program that counts up the occurrences of
signatures in a syslog file. The lines look like

Dec 11 12:50:00 plato snort[6090]: IDS159 - PING Microsoft Windows:
203.94.158.6 -> 203.103.135.130

I want to capture "IDS159 - PING Microsoft Windows", so in a loop I use
($first, $second, $third, $sig) = split /:/, $_;

I am only interested in the contents of the $sig variable - $first,
$second and $third are never used. The program works fine, but the
above line is inelegant. Is there a better method?


Thanks very much in advance,

Ash.


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


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

Date: Mon, 11 Dec 2000 00:51:05 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: There must be a better way
Message-Id: <Pine.GSO.4.21.0012110050250.19179-100000@crusoe.crusoe.net>

[posted & mailed]

On Dec 11, Ash said:

>Dec 11 12:50:00 plato snort[6090]: IDS159 - PING Microsoft Windows:
>203.94.158.6 -> 203.103.135.130
>
>I want to capture "IDS159 - PING Microsoft Windows", so in a loop I use
>($first, $second, $third, $sig) = split /:/, $_;
>
>I am only interested in the contents of the $sig variable - $first,
>$second and $third are never used. The program works fine, but the
>above line is inelegant. Is there a better method?

You could explicitly only use the 4th value returned by split():

  $wanted = (split /:/)[3];

-- 
Jeff "japhy" Pinyan     japhy@pobox.com    http://www.pobox.com/~japhy/
CPAN - #1 Perl Resource  (my id:  PINYAN)       http://search.cpan.org/
PerlMonks - An Online Perl Community          http://www.perlmonks.com/
The Perl Archive - Articles, Forums, etc.   http://www.perlarchive.com/



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

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


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