[23624] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5831 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 19 18:10:35 2003

Date: Wed, 19 Nov 2003 15:10:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 19 Nov 2003     Volume: 10 Number: 5831

Today's topics:
    Re: Need some help... <xaonon@hotpop.com>
    Re: Need some help... <uri@stemsystems.com>
    Re: Need some help... <emschwar@pobox.com>
    Re: Need some help... (Tad McClellan)
    Re: Need some help... <noreply@gunnar.cc>
    Re: Need some help... <xx087@freenet.carleton.ca>
    Re: Need some help... <pasdespam_desmond@zeouane.org>
    Re: Need some help... <usenet@morrow.me.uk>
    Re: Need some help... <noreply@gunnar.cc>
    Re: Need some help... <pasdespam_desmond@zeouane.org>
    Re: Protecting Source code of a perl script (Carlton Brown)
        RegEx problem (Randy)
    Re: RegEx problem <ben@liddicott.com>
    Re: RegEx problem <noreply@gunnar.cc>
        trying to grep a $line for $line...any ideas? <nacs@nb.sympatico.ca>
        Tutorial using AI::NeuralNet::SOM (Imara)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 19 Nov 2003 19:05:16 GMT
From: Xaonon <xaonon@hotpop.com>
Subject: Re: Need some help...
Message-Id: <slrnbrnfmg.t2n.xaonon@xaonon.local>

Ned i bach <99977611.0311191052.3c1f5ff1@posting.google.com>, warpman
<warpman999@netscape.net> teithant i thiw hin: 

> I need some help. I'm new to perl and I have borrow the following
> code. This sub keeps on given me the following date:
> 
> November 5, 103 at 10:16:33:
> 
> I don't understand why it keeps on given me the year as 1xx instead of
> 2 digits. Any help would be greatly appreciated. Thanks in advanced.

perldoc -f localtime

-> $year is the number of years since 1900.  That is, $year is 123 in year
-> 2023.... The proper way to get a complete 4-digit year is simply:
-> 
->     $year += 1900;
-> 
-> And to get the last two digits of the year (e.g., '01' in 2001) do:
-> 
->     $year = sprintf("%02d", $year % 100);

-- 
Xaonon, EAC Chief of Mad Scientists and informal BAAWA, aa #1821, Kibo #: 1
http://xaonon.dyndns.org/  Guaranteed content-free since 1999.  No refunds.
"Uploading isn't a >H goal because it's one step closer to some mythical and
unknowable perfection, but because it'll be jolly practical." -- Rich Artym


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

Date: Wed, 19 Nov 2003 19:09:07 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Need some help...
Message-Id: <x7ekw4dvl8.fsf@mail.sysarch.com>


put the subject in the subject of the post.

did you steal/borrow/copy this code or create this mess yourself? it
looks like typical old cargo cult crap.

this code is so perl4ish and so clunky.

jeez, a y2k bug 3 years later.

rtfm some more on localtime.

no strict

some unseen and probably bad cgi parser is used

quoted scalar variables

it is not worth fixing. dump it all and rewrite it.

you should learn some perl from a better source too.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 19 Nov 2003 12:05:49 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Need some help...
Message-Id: <eto7k1wxjoy.fsf@fc.hp.com>

warpman999@netscape.net (warpman) writes:
> I need some help. I'm new to perl and I have borrow the following
> code. This sub keeps on given me the following date:
>
> November 5, 103 at 10:16:33:
>
> I don't understand why it keeps on given me the year as 1xx instead of
> 2 digits. Any help would be greatly appreciated. Thanks in advanced.

If in doubt, read the documentation:

$ perldoc -f localtime

If you get undesired output from a function, it's best to figure out
whether its your expectations or its that are being confounded.

In this specific case, I'd recommend you use the strftime() function
from the POSIX module.  'perldoc POSIX' for more info.

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


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

Date: Wed, 19 Nov 2003 13:14:28 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Need some help...
Message-Id: <slrnbrng8k.ies.tadmc@magna.augustmail.com>

warpman <warpman999@netscape.net> wrote:

> Subject: Need some help...


Please put the subject of your article in the Subject of your article.


> This sub keeps on given me the following date:
> 
> November 5, 103 at 10:16:33:
> 
> I don't understand why it keeps on given me the year as 1xx instead of
> 2 digits. 


Are you really using four year old code?

It is pretty late in the game for fixing y2k problems...


>    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> localtime(time);


You should read the documentation for the functions that you use:

   perldoc -f localtime

               Note that the $year element is not simply the last
               two digits of the year.  If you assume it is, then
               you create non-Y2K-compliant programs--and you
               wouldn't want to do that, would you?

               The proper way to get a complete 4-digit year is
               simply:

                       $year += 1900;

               And to get the last two digits of the year (e.g.,
               '01' in 2001) do:

               ...


>    if ($sec < 10) {
>       $sec = "0$sec";
>    }


This code is worth what you paid for it (or less).


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


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

Date: Wed, 19 Nov 2003 20:14:25 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Need some help...
Message-Id: <bpgfrv$1o5ils$1@ID-184292.news.uni-berlin.de>

warpman wrote:
> ... I have borrow the following code.

You should not use fragments of other people's code if you don't
understand how it works!

> This sub keeps on given me the following date:
> 
> November 5, 103 at 10:16:33:
> 
> I don't understand why it keeps on given me the year as 1xx instead
> of 2 digits.

Well, you have this line:

     $long_date = "$months[$mon] $mday, $year at $hour\:$min\:$sec";

and the value of $year was grabbed via:

     ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
       = localtime(time);

To understand how a Perl function such as localtime() works, you'd
better study its documentation:

     http://www.perldoc.com/perl5.8.0/pod/func/localtime.html

That should give you what you need to solve the problem.

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



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

Date: 19 Nov 2003 19:30:16 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Need some help...
Message-Id: <slrnbrnh7l.5ra.xx087@smeagol.ncf.ca>

warpman <warpman999@netscape.net> wrote:
>  I need some help. I'm new to perl and I have borrow the following
>  code. This sub keeps on given me the following date:
>  
>  November 5, 103 at 10:16:33:
[...]

Put this line at top of your script:
    use POSIX qw(strftime);

Then, replace all the stuff below with these 3 lines:

    my @now = localtime;
    $date = strftime(($use_time ? '%T ' : '') . '%m/%d/%Y', @now);
    $long_date = strftime('%B %e, %Y at %T', @now);


Read up on chomp() in place of your "chop() if ...";


>     ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
>  localtime(time);
>  
>     if ($sec < 10) {
>        $sec = "0$sec";
>     }
>     if ($min < 10) {
>        $min = "0$min";
>     }
>     if ($hour < 10) {
>        $hour = "0$hour";
>     }
>     if ($mon < 10) {
>        $mon = "0$mon";
>     }
>     if ($mday < 10) {
>        $mday = "0$mday";
>     }
>  
>     $month = ($mon + 1);
>  
>     @months = ("January","February","March","April","May","June","July","August","September","October","November","December");
>  
>     if ($use_time == 1) {
>        $date = "$hour\:$min\:$sec $month/$mday/$year";
>     }
>     else {
>        $date = "$month/$mday/$year";
>     }
>     chop($date) if ($date =~ /\n$/);
>  
>     $long_date = "$months[$mon] $mday, $year at $hour\:$min\:$sec";
>     # $long_date = "$months[$mon] $mday, 19$year at $hour\:$min\:$sec";
>  }


-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


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

Date: Wed, 19 Nov 2003 20:38:51 +0100
From: Desmond Coughlan <pasdespam_desmond@zeouane.org>
Subject: Re: Need some help...
Message-Id: <bfts81-bq4.ln1@zeouane.org>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote ... 

>> ... I have borrow the following code.

> You should not use fragments of other people's code if you don't
> understand how it works!

Are you sure about that ?  It'd mean that I'd use others' code ... erm ...
never.

-- 
Desmond Coughlan               |desmond [at] zeouane [dot] org
http://www.zeouane.org/ 


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

Date: Wed, 19 Nov 2003 19:40:43 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Need some help...
Message-Id: <bpggvr$hlp$2@wisteria.csv.warwick.ac.uk>


Desmond Coughlan <pasdespam_desmond@zeouane.org> wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote ... 
> > You should not use fragments of other people's code if you don't
> > understand how it works!
> 
> Are you sure about that ?  It'd mean that I'd use others' code ... erm ...
> never.

Absolutely!

Note there is an important difference between copy/pasting other
people's code and writing to a documented API. The API is what
relieves you of the responsibility to understand what is going on
and places it on the maintainer. 

Ben

-- 
I've seen things you people wouldn't believe: attack ships on fire off the
shoulder of Orion; I've watched C-beams glitter in the darkness near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die.  |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-|  ben@morrow.me.uk


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

Date: Wed, 19 Nov 2003 20:36:43 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Need some help...
Message-Id: <bpgh5r$1o3lln$1@ID-184292.news.uni-berlin.de>

Desmond Coughlan wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote ... 
>>You should not use fragments of other people's code if you don't
>>understand how it works!
> 
> Are you sure about that ?  It'd mean that I'd use others' code ... erm ...
> never.

Well, I said *fragments of* ...  I meant to distinguish between using 
a module, which is a complete whole intended to be used by others, and 
just copying a fragment of code from somewhere.

Sorry if I was unclear.

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



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

Date: Wed, 19 Nov 2003 20:51:56 +0100
From: Desmond Coughlan <pasdespam_desmond@zeouane.org>
Subject: Re: Need some help...
Message-Id: <s7us81-pt4.ln1@zeouane.org>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote ... 

>>>You should not use fragments of other people's code if you don't
>>>understand how it works!

>> Are you sure about that ?  It'd mean that I'd use others' code ... erm ...
>> never.

> Well, I said *fragments of* ...  I meant to distinguish between using 
> a module, which is a complete whole intended to be used by others, and 
> just copying a fragment of code from somewhere.
> 
> Sorry if I was unclear.

S'all right: my response was tongue-in-cheek anyway.  I mean, come on: I
_know_ Perl, damnit !!

<aside: right, how does this 'hello world' stuff work ...............?>

- -- 
Desmond Coughlan               |desmond [at] zeouane [dot] org
http://www.zeouane.org/ 

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 5.0i for non-commercial use
Charset: noconv

iQA/AwUBP7u7zGiD+5zjSqyTEQLkEgCg2h6o3ziRbcMBGSshwZVC/OHwNgAAnjj5
INpWfvbcuG+4t9T8ynTNakHN
=tW+w
-----END PGP SIGNATURE-----


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

Date: 19 Nov 2003 14:37:11 -0800
From: carltonbrown@hotmail.com (Carlton Brown)
Subject: Re: Protecting Source code of a perl script
Message-Id: <aa611a32.0311191437.43840614@posting.google.com>

"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message news:<Xns94384AEC3609Dsdn.comcast@216.196.97.136>..
> [ snips }
> What makes you think that hiding the source code will make your application 
> more secure?  Typically, a dedicated cracker will figure out what the 
> program is doing and find a way around it anyhow, while your program may 
> not be reviewed for bugs or security holes by your peers.

"Hey world, come look at my source, I dare you to find a hole in my
exhaustively checked and peer-reviewed code."  I wouldn't bet my job
on that philosophy, and I don't think it's fair to belittle the
question of obfuscation.   There's something to be said for not
tempting the amateurs, because now and then they get lucky.  But the
point is well taken... don't feel too comfy if your security strategy
depends solely on obfuscation.


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

Date: 19 Nov 2003 13:36:02 -0800
From: hosshp@yahoo.com (Randy)
Subject: RegEx problem
Message-Id: <3d4770c2.0311191336.700549ef@posting.google.com>

I am trying to take a string out of a line of a log.  I have been able
to identify the line, but when I try to get just the section I want,
it keeps coming back blank.  I was wondering if anyone could tell me
where I am going wrong?

Example of a line of the log file:
20031118,163237,1=1,11=69.6.26.10,21=kschonni@usd.edu,23=4670,1107=.expresstone.com,22=USDSPAMALERT:Order
Reliable Online Prescription
Medication,52=M2003111816285500014,20=expresstoneA@mx01.expresstone.com,100=Message
from an email address marked as a
spammer.,24=b.expresstoneA.0-274725f-1f61.usd.edu.-kschonni@mx01.expresstone.com,2=307,121=8

2=307 lets me know it is the line that I want, and, the part of it
that I need to use is after 1107=.  So in this example, it would be
'.expresston.com'.  I have been trying to get the whole part
(1107=.expresston.com) but have only been getting back blank returns. 
Here is the expression I have been trying:

$line =~ /1107=\.\w\.\w/;
$temp = $1;

If someone could let me know where I am going wrong, I would really
appreciate it.
Thanks,
Randy


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

Date: Wed, 19 Nov 2003 22:07:43 +0000 (UTC)
From: "Ben Liddicott" <ben@liddicott.com>
Subject: Re: RegEx problem
Message-Id: <bpgpjf$o8n$1@titan.btinternet.com>

\w matches a single word character [a-zA-Z0-9_], not a "word". You need =
\w+ to match a word.

Furthermore, you don't actually want a word character. DNS names often =
contain a dash, which won't be matched by \w.

What you need is this:

m/
    \,1107\=3D    # a comma, then 1107=3D
    ([^,]+)\,        # match everything up to the next comma.
/x                    # x says I can put comments and whitespace in the =
regex.


In this case, I suspect you would be just as well using split to chop it =
up by commas, and map to make a hashref of the fields.

Something like this:

#$sLine is the line
%fields =3D map(sub{
    if($_ =3D~ m/\=3D/){
        return $_ =3D~ m/([^=3D]+)\=3D(.*)/;
    }
},   split(',', $sLine));

Then you can say=20
if($fields{2} =3D=3D 307){
    my $whatIWantToKnow =3D $fields{1107};
}


--=20
Cheers,
Ben Liddicott

"Randy" <hosshp@yahoo.com> wrote in message =
news:3d4770c2.0311191336.700549ef@posting.google.com...
> I am trying to take a string out of a line of a log.  I have been able
> to identify the line, but when I try to get just the section I want,
> it keeps coming back blank.  I was wondering if anyone could tell me
> where I am going wrong?
>=20
> Example of a line of the log file:
> =
20031118,163237,1=3D1,11=3D69.6.26.10,21=3Dkschonni@usd.edu,23=3D4670,110=
7=3D.expresstone.com,22=3DUSDSPAMALERT:Order
> Reliable Online Prescription
> =
Medication,52=3DM2003111816285500014,20=3DexpresstoneA@mx01.expresstone.c=
om,100=3DMessage
> from an email address marked as a
> =
spammer.,24=3Db.expresstoneA.0-274725f-1f61.usd.edu.-kschonni@mx01.expres=
stone.com,2=3D307,121=3D8
>=20
> 2=3D307 lets me know it is the line that I want, and, the part of it
> that I need to use is after 1107=3D.  So in this example, it would be
> '.expresston.com'.  I have been trying to get the whole part
> (1107=3D.expresston.com) but have only been getting back blank =
returns.=20
> Here is the expression I have been trying:
>=20
> $line =3D~ /1107=3D\.\w\.\w/;
> $temp =3D $1;
>=20
> If someone could let me know where I am going wrong, I would really
> appreciate it.
> Thanks,
> Randy


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

Date: Wed, 19 Nov 2003 23:29:20 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: RegEx problem
Message-Id: <bpgraa$1nef93$1@ID-184292.news.uni-berlin.de>

Ben Liddicott wrote:
> In this case, I suspect you would be just as well using split to
> chop it up by commas, and map to make a hashref of the fields.
> 
> Something like this:
> 
> #$sLine is the line
> %fields = map(sub{
>     if($_ =~ m/\=/){
>         return $_ =~ m/([^=]+)\=(.*)/;
>     }
> },   split(',', $sLine));
> 
> Then you can say 
> if($fields{2} == 307){
>     my $whatIWantToKnow = $fields{1107};
> }

Uhmm..  What would the point be with all that, when you can simply do

     $line =~ /1107=([^,]+)/;
     print $1;

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



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

Date: Wed, 19 Nov 2003 22:28:37 GMT
From: "Joshua Sparks" <nacs@nb.sympatico.ca>
Subject: trying to grep a $line for $line...any ideas?
Message-Id: <p8Sub.32121$R13.933931@ursa-nb00s0.nbnet.nb.ca>

Newbie here,

I"ve written a perl program which is basically working with one exception.
I've got a text file called exceptions.txt and I need to process (see code
snippet)
What needs to happen is that I am checking the contents of one line of a
text file (INPUT) against
the contents of one line of another text file (INPUT1).  If I find INPUT1
anywhere on INPUT,
I want to flag it as found so I can ignore it.  However, despite the fact
that $check_line is contained
in $line, my print statement isn't executing and therefor the flag isn't
working.  I've tried using regular expressions (should be simple)
and also a grep but nothing seems to work.

I need this code to work so I can ignore certain things.  There's probably a
better way to write this but for my purposes, I just
need to ensure that my grep or reg. expr. will work.



 .
 .
    $file=shift;
    my($found_bad);
    open(INPUT, "< $file") or warn "Couldn't process $file";
    while ($line = <INPUT>)
    {
      $found_bad=0;
      open(INPUT1, "< exceptions.txt") or die "you screwed up";
      while ($check_line = <INPUT1>)
       {
         print ("Checking $line for $check_line \n");
         if ($line =~ m/$check_line/)
    {
      print ("I found $check_line in $line \n");
             $found_bad = 1;
            }
        }
      close(INPUT1);
 .
 .
 .




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

Date: 19 Nov 2003 12:48:30 -0800
From: azzaric@hotmail.com (Imara)
Subject: Tutorial using AI::NeuralNet::SOM
Message-Id: <ec243dc3.0311191248.8b2e4f@posting.google.com>

Does anyone know of a simple tutorial, or example using the Perl
module, AI::NeuralNet::SOM?  Something that breaks things down a
little better than the documentation.

Thanks in advance!


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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


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


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