[23626] in Perl-Users-Digest
Perl-Users Digest, Issue: 5833 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 20 00:05:53 2003
Date: Wed, 19 Nov 2003 21:05:08 -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: 5833
Today's topics:
Comments: locking variables <mb@uq.net.au.invalid>
Re: Comments: locking variables (Jay Tilton)
Re: Comments: locking variables (Jay Tilton)
Re: god im a noob Default@User011011101101.net
Re: god im a noob (Tad McClellan)
Re: god im a noob <mgjv@tradingpost.com.au>
Re: god im a noob Default@User011011101101.net
Re: god im a noob (Sam Holden)
Re: god im a noob Default@IO_Error_1011101.xyz
Re: god im a noob (Tad McClellan)
Re: How do I substitute the 2nd occurance of a comma fr <tore@aursand.no>
Re: Image::Info::TIFF - multi-page tiff images page cou (ifiaz)
Re: Image::Info::TIFF - multi-page tiff images page cou <mgjv@tradingpost.com.au>
Re: Program that prints its source code <usenet@dwall.fastmail.fm>
Re: Protecting Source code of a perl script (James Willmore)
Re: RegEx problem (Tad McClellan)
Re: RegEx problem <noreply@gunnar.cc>
Re: test please ignore <jurgenex@hotmail.com>
Re: test please ignore (Tad McClellan)
Re: test please ignore <kkeller-usenet@wombat.san-francisco.ca.us>
Re: test please ignore Default@User011011101101.net
Re: test please ignore <asu1@c-o-r-n-e-l-l.edu>
Re: test please ignore (Tad McClellan)
Re: trying to grep a $line for $line...any ideas? <tore@aursand.no>
Re: trying to grep a $line for $line...any ideas? (Sam Holden)
Re: trying to grep a $line for $line...any ideas? <nacs@nb.sympatico.ca>
Re: trying to grep a $line for $line...any ideas? (Sam Holden)
Re: trying to grep a $line for $line...any ideas? <noreply@gunnar.cc>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 20 Nov 2003 13:12:30 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Comments: locking variables
Message-Id: <bphbeu$8lu$1@bunyip.cc.uq.edu.au>
Hi all,
I need to lock down some keys in a blessed hash so that they cannot be
directly altered (eg through $self->{key} = "whatever"). This is
important as the key in question holds a security flag for the current
instance, and I don't want it to be _too_ easy to circumvent :)
I can't use the class extensions that perl5 has (due to perceived
'flimsyness' by the powers-that-be), but I've worked around this using
Tie::Watch (which, since it is in existing programs here, is apparently ok).
So, I'm now doing something like:
package Whatever;
require Tie::Watch;
my $WriteLock = sub {die "Attempt to alter protected data"};
my $DeleteLock = sub {my ($self, $watch) = @_;
$watch->Unwatch;
$self->_close()};
...
sub _initialise {
my $self = shift;
... # Set $self->{AltUID}
Tie::Watch->new(-variable => \$self->{AltUID},
-store => $WriteLock,
-destroy => sub {$DeleteLock->($self, $_[0])});
eval {$self->{AltUID} = -1};
if (not $@ or $@ !~ /Attempt to alter protected data/) {
die "Failed to protect data";
}
...
}
sub close {
my $self = shift;
delete($self->{AltUID}); # Watch will close for me
}
sub _close {
my $self = shift;
$self = {}; # Now useless for all but new
}
This means that any attempt to alter the AltUID key results in a die
(and even if its caught, the data remains unchanged), while trying to
delete that key (and then replace it) results in the object closing and
becoming useless for anything other than another new call. Of course,
you can still read the data directly, but in this case that's ok.
A direct call to $self->_close still works, although if it had caused
problems (like a segfault or some other unexpected horribleness) I
wouldn't have been worried - the user's not supposed to call that anyway.
So, is this a good way of doing it? Problems? Etc? :)
MB
------------------------------
Date: Thu, 20 Nov 2003 04:29:51 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Comments: locking variables
Message-Id: <3fbc42fc.199182978@news.erols.com>
Matthew Braid <mb@uq.net.au.invalid> wrote:
: I need to lock down some keys in a blessed hash so that they cannot be
: directly altered (eg through $self->{key} = "whatever").
The lock_keys() function in the Hash::Util module is perfectly suited.
------------------------------
Date: Thu, 20 Nov 2003 04:41:49 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Comments: locking variables
Message-Id: <3fbc459d.199855293@news.erols.com>
tiltonj@erols.com (Jay Tilton) wrote:
: Matthew Braid <mb@uq.net.au.invalid> wrote:
:
: : I need to lock down some keys in a blessed hash so that they cannot be
: : directly altered (eg through $self->{key} = "whatever").
:
: The lock_keys() function in the Hash::Util module is perfectly suited.
Sorry. You evidently want the hash _values_ to be read-only. The
lock_value function can do that.
------------------------------
Date: Thu, 20 Nov 2003 02:29:35 GMT
From: Default@User011011101101.net
Subject: Re: god im a noob
Message-Id: <jGVub.53103$bQ3.6515@nwrdny03.gnilink.net>
>
> Default@User011011101101.net wrote:
>
> > snip
>
> Please put the main topic of your post in the Subject field.
>
>
ok, sry bout that..
------------------------------
Date: Wed, 19 Nov 2003 20:38:48 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: god im a noob
Message-Id: <slrnbroa9o.1no.tadmc@magna.augustmail.com>
Default@User011011101101.net <Default@User011011101101.net> wrote:
>> Default@User011011101101.net wrote:
>>
>> > snip
>>
>> Please put the main topic of your post in the Subject field.
>>
>>
> ok, sry bout that..
^^^ ^^^^
^^^ ^^^^
Please don't use cutsie spelling either, it is inconsiderate
of those whose first language is not English.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 20 Nov 2003 04:00:41 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: god im a noob
Message-Id: <slrnbrof3c.q43.mgjv@verbruggen.comdyn.com.au>
On Thu, 20 Nov 2003 01:34:37 GMT,
Default@User.xyz <Default@User.xyz> wrote:
> curious; does anyone ever try the programs listed?
> here is the output...
You need to start listening to what people say. The solution to your
problem, and the error you made was explained in at least two posts in
this thread.
And yes, I did run your code, even though I didn't need to to find the
problem.
Did you read the responses you got?
Martien
--
|
Martien Verbruggen |
Trading Post Australia | What's another word for Thesaurus?
|
------------------------------
Date: Thu, 20 Nov 2003 04:05:54 GMT
From: Default@User011011101101.net
Subject: Re: god im a noob
Message-Id: <C4Xub.53356$bQ3.52442@nwrdny03.gnilink.net>
Yes, i just finally got the reply's and like 1000 other
messages.. thanks alot for the tips ill try that. This nntp isnt very good,
perhaps there is a perl bbs?
> On Thu, 20 Nov 2003 01:34:37 GMT,
> Default@User.xyz <Default@User.xyz> wrote:
> > curious; does anyone ever try the programs listed?
> > here is the output...
>
> You need to start listening to what people say. The solution to your
> problem, and the error you made was explained in at least two posts in
> this thread.
>
> And yes, I did run your code, even though I didn't need to to find the
> problem.
>
> Did you read the responses you got?
>
> Martien
> --
> |
> Martien Verbruggen |
> Trading Post Australia | What's another word for Thesaurus?
> |
>
------------------------------
Date: 20 Nov 2003 04:09:42 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: god im a noob
Message-Id: <slrnbrofk6.2qb.sholden@flexal.cs.usyd.edu.au>
On 20 Nov 2003 04:00:41 GMT, Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> On Thu, 20 Nov 2003 01:34:37 GMT,
> Default@User.xyz <Default@User.xyz> wrote:
>> curious; does anyone ever try the programs listed?
>> here is the output...
>
> You need to start listening to what people say. The solution to your
> problem, and the error you made was explained in at least two posts in
> this thread.
>
> And yes, I did run your code, even though I didn't need to to find the
> problem.
>
> Did you read the responses you got?
They'll be the last, I suspect. I wasted more seconds than the poster
deserved already (and have added two killfile entries already, due to
the address munge change)... So best read them thouroughly :)
--
Sam Holden
------------------------------
Date: Thu, 20 Nov 2003 04:46:56 GMT
From: Default@IO_Error_1011101.xyz
Subject: Re: god im a noob
Message-Id: <4HXub.37927$hB5.13787@nwrdny02.gnilink.net>
> #!
> use strict;
> use warnings;
> my $database = "Numbers and Colors";
> verify_data_entry();
>
> #Subroutines#
> sub data_entry
> {
> print "\nEnter a number: ";
> chomp (my $number = <STDIN>); $number =~ s/\W.*//;
> print "\nEnter some colors (ctrl-z when finished):\n";
> chomp (my @colors_in = <STDIN>);
> foreach my $item (@colors_in)
> {$item =~ s/\W.*//; $item = ucfirst (lc($item));}
> my $aref_1 = [@colors_in];
> my %numbers_colors = ($number, $aref_1);
> verify_data_entry();
> print "\n$database has been updated with the following entries.\n";
> foreach my $key (sort keys %numbers_colors)
> {
> my @colors_out1 = @{$numbers_colors{$key}};
> my $colors_out2 = join ', ', sort @colors_out1;
> print "$key\t$colors_out2\n";
> }
> print "\nWhy does this print between each key?\n"; # why ?!
#
# ok i cut out the dmbopen bit... for clarity
# see it prints the "Why does this blah blah blah" bit
#
# but then can you explain to me why it didnt just exit the program
# and instead it goes to the foreach line after it already exited the
# curley bracers?
# its obvious its not exiting the sub cause it doesnt ask for another
# number and besides
# that print is the last command it the whole code.
# I mean after it prints "Why does this blah blah blah.." the first time..
#whats the next thing in the code? nothing.
# so why is the next thing it does is start the foreach over?
# why not jump to line 6?
#
> }
> sub verify_data_entry
> {
> print "\nEnter data into $database database? (y or n): ";
> chomp (my $verify = lc<STDIN>);
> data_entry() if ($verify eq "y");
> }
>
PS - sorry for not using a proper subject. i read the faq thing.
------------------------------
Date: Wed, 19 Nov 2003 22:40:19 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: god im a noob
Message-Id: <slrnbrohdj.1qg.tadmc@magna.augustmail.com>
Default@User011011101101.net <Default@User011011101101.net> wrote:
> This nntp isnt very good,
> perhaps there is a perl bbs?
You know that is the fault of your ISP and not of clp.misc don't you?
Switch to an ISP with a better news feed.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 20 Nov 2003 03:15:27 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: How do I substitute the 2nd occurance of a comma from a text file
Message-Id: <pan.2003.11.20.01.52.54.105272@aursand.no>
On Wed, 19 Nov 2003 08:04:41 -0800, Greg Gallagher wrote:
> Thanks to everyone who offered help. Tore, you obviously have worked
> with csv files before!!
Actually, no, but I'm good at parsing data myself. :-)
> I checked out cpan and found some whizzy code which has pretty much
> sorted out the problem with some horrid data :o)
Well. Do _not_ extract the solutions provided in the modules. Install
the modules themselves and use them as described in the documentation.
If you want to learn from the code - go ahead, but don't do that when
producing production code.
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: 19 Nov 2003 18:22:11 -0800
From: ifiaz@hotmail.com (ifiaz)
Subject: Re: Image::Info::TIFF - multi-page tiff images page count
Message-Id: <93c1947c.0311191822.2c9d184e@posting.google.com>
> Image::Magick will be able to tell you this. You open the image as an
> IM object, and then you just count the number of elements in it.
>
> Note that Image::Magick generally relies on an external tiff library
> to write and read images.
Thanks for your suggestions.
I am using Mac OS X, 10.2.8 with perl 5.6.0.
As I don't have Image::Magick in the /System/Library/Perl, I tried to download
it from the CPAN website for PerlMagick-5.57.tar.gz. After the download
completes, I can't follow the instructions from the README.
First hurdle:
local.:~/Desktop/PerlMagick-5.57> perl Makefile.PL
Checking if your kit is complete...
Looks good
Note (probably harmless): No library found for -lMagick
Note (probably harmless): No library found for -llcms
Note (probably harmless): No library found for -lexif
Writing Makefile for Image::Magick
And afterwards I typed 'make' and lots of errors.
I have no idea how I can have it installed in my system.
If anyone can assist, please...
------------------------------
Date: 20 Nov 2003 04:05:18 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Image::Info::TIFF - multi-page tiff images page count
Message-Id: <slrnbrofc1.q43.mgjv@verbruggen.comdyn.com.au>
On 19 Nov 2003 18:22:11 -0800,
ifiaz <ifiaz@hotmail.com> wrote:
>> Image::Magick will be able to tell you this. You open the image as an
>> IM object, and then you just count the number of elements in it.
>>
>
>> Note that Image::Magick generally relies on an external tiff library
>> to write and read images.
>
> Thanks for your suggestions.
>
> I am using Mac OS X, 10.2.8 with perl 5.6.0.
>
> As I don't have Image::Magick in the /System/Library/Perl, I tried to download
> it from the CPAN website for PerlMagick-5.57.tar.gz. After the download
> completes, I can't follow the instructions from the README.
You need the ImageMagick library first. The best thing to do is
download the complete IMageMagick distribution from imagemagick.org,
and install the Perl module from that distribution. That way you have
it all in sync.
Maybe you can get some precompiled stuff from whoever provided Perl
for you? Does Apple have their own repository?
That said, I don't really know whether it is supported on MacOSX. The
documentation seems to suggest that the Unix source should work on
MacOS 10.
Start with unpacking the source, run configure --without-perl (and
whatever other options you need) and make, and install. Change to the
PerlMagick directory, run perl Makfile.PL, make, make test and make
install.
Martien
--
|
Martien Verbruggen |
Trading Post Australia | Curiouser and curiouser, said Alice.
|
------------------------------
Date: Thu, 20 Nov 2003 03:02:03 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Program that prints its source code
Message-Id: <Xns9438E02619C86dkwwashere@216.168.3.30>
Michele Dondi <bik.mido@tiscalinet.it> wrote:
> On Tue, 18 Nov 2003 18:56:02 -0000, "David K. Wall"
><usenet@dwall.fastmail.fm> wrote:
>
>>If I want a program to print its own source code, is there any reason
>>to prefer one of these code snippets over the other? Or is there an
>>even better way to do it?
>
> This is called a 'quine'. Try and search this NG for that word on
> google!
I once knew that... :-)
>>Snippet 1:
>>
>>seek DATA, 0, 0;
>>print <DATA>;
>>__DATA__
>>
>>Snippet 2:
>>
>>open SELF, $0 or die "Error opening self for reading";
>>print <SELF>;
>
> I think that these would be considered both "illegal" quines for most
> definitions of quine.
Yeah, well, this wasn't for a contest or anything, just a toy program I
wrote that I wanted to make available to other people for them to play with
or extend if they were interested. It's completely trivial, but fun, so
here's the program: http://ylatis.com/cgi-bin/tile
--
David Wall
------------------------------
Date: 19 Nov 2003 18:20:20 -0800
From: jwillmore@myrealbox.com (James Willmore)
Subject: Re: Protecting Source code of a perl script
Message-Id: <d61170e5.0311191820.533dc1f4@posting.google.com>
Senthilraja <senthil.raja@adcc.alcatel.be> wrote in message news:<3FBB1913.2CF04140@adcc.alcatel.be>...
> I've written a perl script for a high security application and hence I
> want to protect the source code of the perl script, even from the
> administrator of the application.
>
> Is there any way to convert the perl script source into some sort of exe
> or binary file, without affecting the functioning of the script?
I'm making a guess that you have passwords in the application and
that's why you really want secured, right? If so, there are ways to
secure the passwords and still run the application - without having to
hide the source code. The same applies to file locations.
Just place the information you need secured into a separate encrypted
file. Make sure the file system permissions are set in such a way as
to prevent snooping. Have the application decrypt the encrypted file.
Take the information from the decrypted file and use in the
application - salt to taste :-)
As far as a key (needed by *most* encryption modules), use an empty
file, get the MD5 checksum (or other algorithim) of the empty file and
use that as the key. Again, file system's permissions need to be set
properly to keep snoops out.
I have used this method successful and have encountered no issues.
There is no realistic way to 'hide' the source of *any* application.
The idea behind computer security is to keep honest people honest (and
snoops out). Absolute security is a myth and an unrealistic
expectation - it does *not* exist.
And so is the myth that compiled code can't be seen. If that
administrator *wants* to see the source for your application, then
s/he will find a way to get it - compiled or not. Quite frankly, if
you trust them that little, then why are they the administrator of
this highly secure application? And have you discussed your concerns
with managment?
HTH
Jim
(jwillmore _at_ adelphia _dot_ net)
------------------------------
Date: Wed, 19 Nov 2003 20:35:52 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: RegEx problem
Message-Id: <slrnbroa48.1no.tadmc@magna.augustmail.com>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> when you can simply do
>
> $line =~ /1107=([^,]+)/;
> print $1;
You _can_ do that, but you _shouldn't_ do that.
You should never use the dollar-digit variables unless
you have first ensured that the match succeeded, because
their values are only set for _successful_ matches.
if ( $line =~ /1107=([^,]+)/ ) {
print $1;
}
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 20 Nov 2003 04:51:14 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: RegEx problem
Message-Id: <bphe70$1o9u0c$1@ID-184292.news.uni-berlin.de>
Tad McClellan wrote:
> Gunnar Hjalmarsson wrote:
>>when you can simply do
>>
>> $line =~ /1107=([^,]+)/;
>> print $1;
>
> You _can_ do that, but you _shouldn't_ do that.
>
> You should never use the dollar-digit variables unless
> you have first ensured that the match succeeded, because
> their values are only set for _successful_ matches.
>
> if ( $line =~ /1107=([^,]+)/ ) {
> print $1;
> }
You are right, I admit that my example was _too_ simplified. The
purpose was to compare the use of a simple regex with creating a hash
representing the whole line.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 20 Nov 2003 02:31:54 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: test please ignore
Message-Id: <uIVub.82639$E9.45166@nwrddc01.gnilink.net>
Default@User011011101101.xyz wrote:
> posts not showing up.. is nntp usually slow like this?
Your wish is my command: PLONK
jue
------------------------------
Date: Wed, 19 Nov 2003 20:43:57 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: test please ignore
Message-Id: <slrnbroajd.1no.tadmc@magna.augustmail.com>
Default@User011011101101.xyz <Default@User011011101101.xyz> wrote:
> Subject: test please ignore
Please don't make off-topic postings.
*plonk*
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 19 Nov 2003 19:03:16 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: test please ignore
Message-Id: <ktahpb.qpb.ln@goaway.wombat.san-francisco.ca.us>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On 2003-11-20, Default@User011011101101.xyz <Default@User011011101101.xyz> wrote:
> posts not showing up.. is nntp usually slow like this?
You really don't want people to help you, do you?
- --keith
- --
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQE/vC7yhVcNCxZ5ID8RAjf6AKCYfjTIwMJ1LgQzTaAv+f0JLVwjYACfQK6P
oT4KEl+Kwu2ASLmI0HHm6BQ=
=hdQL
-----END PGP SIGNATURE-----
------------------------------
Date: Thu, 20 Nov 2003 03:45:08 GMT
From: Default@User011011101101.net
Subject: Re: test please ignore
Message-Id: <8NWub.37848$hB5.1619@nwrdny02.gnilink.net>
shrug, dont be a douchebag.. im just not used to nntp
and my original post of "test please igonre" still isnt even showing up.
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> On 2003-11-20, Default@User011011101101.xyz <Default@User011011101101.xyz> wrote:
> > posts not showing up.. is nntp usually slow like this?
>
> You really don't want people to help you, do you?
>
> - --keith
>
> - --
> kkeller-usenet@wombat.san-francisco.ca.us
> (try just my userid to email me)
> AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
>
> -----BEGIN xxx SIGNATURE-----
> Version: GnuPG v1.2.3 (GNU/Linux)
>
> iD8DBQE/vC7yhVcNCxZ5ID8RAjf6AKCYfjTIwMJ1LgQzTaAv+f0JLVwjYACfQK6P
> oT4KEl+Kwu2ASLmI0HHm6BQ=
> =hdQL
> -----END PGP SIGNATURE-----
>
------------------------------
Date: 20 Nov 2003 04:05:05 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: test please ignore
Message-Id: <Xns9438EAD60D034asu1cornelledu@132.236.56.8>
Default@User011011101101.net wrote in
news:8NWub.37848$hB5.1619@nwrdny02.gnilink.net:
>> On 2003-11-20, Default@User011011101101.xyz
>> <Default@User011011101101.xyz> wrote:
>> > posts not showing up.. is nntp usually slow like this?
>>
>> You really don't want people to help you, do you?
>>
>> - --keith
>
> shrug, dont be a douchebag..
You are intent on making sure no one will ever care to answer your
questions.
> im just not used to nntp and my original post of
> "test please igonre" still isnt even showing up.
Are you sure this is not related to the settings of your newsreader?
Posting test messages to non-test groups is a no-no. Cursing at people
after such a faux pas is even worse.
Writing in baby talk is what gives away the fact that you are not to be
taken seriously.
Good bye.
Sinan.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Wed, 19 Nov 2003 22:43:40 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: test please ignore
Message-Id: <slrnbrohjs.1qg.tadmc@magna.augustmail.com>
Default@User011011101101.net <Default@User011011101101.net> wrote:
> dont be a douchebag.. im just not used to nntp
If you are new to Usenet, then you can't know what constitutes
being a douche bag here.
I've see that a bunch of folks who _do_ have experience with Usenet
who seem to have made such a connection though.
One newbie is right, and the many with experience are wrong?
Yeah, right.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 20 Nov 2003 03:15:27 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: trying to grep a $line for $line...any ideas?
Message-Id: <pan.2003.11.20.02.07.06.681903@aursand.no>
On Wed, 19 Nov 2003 22:28:37 +0000, Joshua Sparks wrote:
> 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.
What exactly is _it_ that you want to flag? I mean, what does that flag
do to your script in real life?
> open(INPUT, "< $file") or warn "Couldn't process $file";
Do you _really_ want to continue if you can't open $file? And why do you
have a space before the filename?
> while ($line = <INPUT>)
You don't want to chomp() off some characters?
> {
> $found_bad=0;
> open(INPUT1, "< exceptions.txt") or die "you screwed up";
You _really_ want to open the file _for each line_ that you read? And
what's that space before the filename again?
> if ($line =~ m/$check_line/)
Do you want to check if $line _contains_ $check_line, or _is equal to_
$check_line?
> {
> print ("I found $check_line in $line \n");
> $found_bad = 1;
> }
> }
Do you really want to continue setting $found_bad to 1 if there are more
hits? Why not consider last() here?
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: 20 Nov 2003 02:52:03 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: trying to grep a $line for $line...any ideas?
Message-Id: <slrnbrob2j.28g.sholden@flexal.cs.usyd.edu.au>
On Thu, 20 Nov 2003 03:15:27 +0100, Tore Aursand <tore@aursand.no> wrote:
> On Wed, 19 Nov 2003 22:28:37 +0000, Joshua Sparks wrote:
>> 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.
>
> What exactly is _it_ that you want to flag? I mean, what does that flag
> do to your script in real life?
>
>> open(INPUT, "< $file") or warn "Couldn't process $file";
>
> Do you _really_ want to continue if you can't open $file? And why do you
> have a space before the filename?
Seperating the file open mode indicator from the filename with whitespace
seems like a reasonable enough style.
Just like the whitespace between the , and the ".
It's not a style I use myself, it is used *once* in the open docs (though
it isn't used in all the other examples, of which there are many).
--
Sam Holden
------------------------------
Date: Thu, 20 Nov 2003 03:02:42 GMT
From: "Joshua Sparks" <nacs@nb.sympatico.ca>
Subject: Re: trying to grep a $line for $line...any ideas?
Message-Id: <m9Wub.32283$R13.945433@ursa-nb00s0.nbnet.nb.ca>
consider 2 "text" files.
INPUT contains:
My name is
Hello you dolt
Learning perl is difficult
I love my job
INPUT2 contains:
name is
dolt
perl
What I want to do is test each line of INPUT to see if it contains the exact
contents of each line of INPUT2. In Pseudo-code it would be
for each line L1 in INPUT
boolean_found <- false
for each line L2 in INPUT2
if L2 in L1
boolean_found <- true
endif
end
end
if boolean_found = false
do some more stuff with L1
I'm not too concerned with LASTs and stuff because INPUT2 is only going to
contain about 10 lines or so.
"Tore Aursand" <tore@aursand.no> wrote in message
news:pan.2003.11.20.02.07.06.681903@aursand.no...
> On Wed, 19 Nov 2003 22:28:37 +0000, Joshua Sparks wrote:
> > 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.
>
> What exactly is _it_ that you want to flag? I mean, what does that flag
> do to your script in real life?
>
> > open(INPUT, "< $file") or warn "Couldn't process $file";
>
> Do you _really_ want to continue if you can't open $file? And why do you
> have a space before the filename?
>
> > while ($line = <INPUT>)
>
> You don't want to chomp() off some characters?
>
> > {
> > $found_bad=0;
> > open(INPUT1, "< exceptions.txt") or die "you screwed up";
>
> You _really_ want to open the file _for each line_ that you read? And
> what's that space before the filename again?
>
> > if ($line =~ m/$check_line/)
>
> Do you want to check if $line _contains_ $check_line, or _is equal to_
> $check_line?
>
> > {
> > print ("I found $check_line in $line \n");
> > $found_bad = 1;
> > }
> > }
>
> Do you really want to continue setting $found_bad to 1 if there are more
> hits? Why not consider last() here?
>
>
> --
> Tore Aursand <tore@aursand.no>
------------------------------
Date: 20 Nov 2003 04:00:30 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: trying to grep a $line for $line...any ideas?
Message-Id: <slrnbrof2t.2qb.sholden@flexal.cs.usyd.edu.au>
On Thu, 20 Nov 2003 03:02:42 GMT, Joshua Sparks <nacs@nb.sympatico.ca> wrote:
> consider 2 "text" files.
>
> INPUT contains:
>
> My name is
> Hello you dolt
> Learning perl is difficult
> I love my job
>
> INPUT2 contains:
>
> name is
> dolt
> perl
>
> What I want to do is test each line of INPUT to see if it contains the exact
> contents of each line of INPUT2. In Pseudo-code it would be
Read INPUT2 into an array and then read INPUT line by line checking each
line against each element in the array.
>
> for each line L1 in INPUT
> boolean_found <- false
> for each line L2 in INPUT2
> if L2 in L1
> boolean_found <- true
> endif
> end
> end
>
> if boolean_found = false
> do some more stuff with L1
Turn it into perl (moving the if into the loop where it belongs):
#read needles
open INPUT2, "input2.txt" or die "Unable to open input2.txt: $!";
chomp (my @needles = <INPUT2>);
close INPUT2;
# open haystack
open INPUT, "input.txt" or die "Unable to open input.txt: $!";
# the line by line psuedo code conversion...
foreach my $line1 (<INPUT>) {
my $boolean_found = 0;
foreach my $line2 (@needles) {
if (index($line1, $line2) != -1) {
$boolean_found = 1;
}
}
if ($boolean_found == 0) {
# do some stuff with $line1
}
}
close INPUT;
The only "tricky" bit how to express L2 in L1, using index seems reasonable
to me, though you could also use a regex.
The outer foreach is inneficient as it reads the entire file at once, so
we can make a simple optimisation by converting it into a while, and
once a match is found there's no need to keep looking so we can
add a last, and the "== 0" is ugly, we can replace it with if (!...) or
unless (...). And the name boolean_found is long, replace with found.:
while (my $line1 = <INPUT>) {
my $found = 0;
foreach my $line2 (@needles) {
if (index($line1, $line2) != -1) {
$found = 1;
last;
}
}
unless ($found) {
# do some stuff with $line1
}
}
We could reduce the nesting by moving the search over the array into
a function such as:
sub contains_a_needle {
my $line = shift;
foreach (@needles) {
return 1 if index($line,$_) != -1;
}
return;
}
Then the main loop simplifies to:
while (my $line = <INPUT>) {
unless (contains_a_needle($line)) {
# do some stuff with $line
}
}
Or even:
for my $line (grep !contains_a_needle($_), <INPUT>) {
# do some stuff with $line
}
At the cost of slurping the file into memory again.
--
Sam Holden
------------------------------
Date: Thu, 20 Nov 2003 05:32:45 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: trying to grep a $line for $line...any ideas?
Message-Id: <bphgl0$1nuc1h$1@ID-184292.news.uni-berlin.de>
Sam Holden wrote:
> Tore Aursand wrote:
>> Joshua Sparks wrote:
>>>
>>> open(INPUT, "< $file") or warn "Couldn't process $file";
>>
>> why do you have a space before the filename?
>
> Seperating the file open mode indicator from the filename with
> whitespace seems like a reasonable enough style.
The "Camel" book (3rd edition, page 565) includes this statement: "If
you intend to use any externally derived data as part of a filename to
open, at least include an explicit mode separated by a space."
Out from that discussion I have concluded that separating them with a
space is not only reasonable enough style, but even preferrable style
when you want your code to be pre 5.6.0 compatible. (Otherwise the
three-argument form is better.)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
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 5833
***************************************