[22450] in Perl-Users-Digest
Perl-Users Digest, Issue: 4671 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 6 03:05:43 2003
Date: Thu, 6 Mar 2003 00:05:12 -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 Thu, 6 Mar 2003 Volume: 10 Number: 4671
Today's topics:
Re: "Stupid File Difference" function/module <krahnj@acm.org>
Re: "Stupid File Difference" function/module <mgjv@tradingpost.com.au>
Re: Boolean statement which triggers on time <josef.moellers@fujitsu-siemens.com>
Re: Can Perl can have the include head file like c? <mgjv@tradingpost.com.au>
Re: Counting matches in a regular expression <goldbb2@earthlink.net>
Re: DBD and DBI on Solaris 64 bit <goldbb2@earthlink.net>
Re: file searching <krahnj@acm.org>
Re: Get directory only once and put it in array with Fi <jurgenex@hotmail.com>
Re: Greedy regexps <steven.smolinski@sympatico.ca>
Re: HELP- How can i use proxy service for port 80 as c (Sade Bhat Kalasabail)
Re: HELP- How can i use proxy service for port 80 as c <abigail@abigail.nl>
Re: How can I write this regex? <goldbb2@earthlink.net>
Re: How to access proxy server for Perl Soap client (Sade Bhat Kalasabail)
Re: perl locks up my win98 computer <james.mcininch@attbi.com>
Re: Perl Mysql uploading a image in a database. <mgjv@tradingpost.com.au>
Re: Print lines of file until certain string found? <krahnj@acm.org>
Re: Print lines of file until certain string found? <peakpeek@purethought.com>
Re: printing hash values <jurgenex@hotmail.com>
Re: printing hash values (Tad McClellan)
Re: printing hash values <dont@want.spam>
Re: Scripts in background <jurgenex@hotmail.com>
Re: Scripts in background <s_grazzini@hotmail.com>
Re: tough regex problem <s_grazzini@hotmail.com>
Re: tough regex problem (Tad McClellan)
Re: tough regex problem (Jay Tilton)
Re: What is wrong with this piece of UDP server code? <goldbb2@earthlink.net>
Re: What is wrong with this piece of UDP server code? <andrew.rich@bigpond.com>
Re: What is wrong with this piece of UDP server code? <wweng@play.cs.columbia.edu>
Re: What is wrong with this piece of UDP server code? <wweng@play.cs.columbia.edu>
Re: What is wrong with this piece of UDP server code? <mgjv@tradingpost.com.au>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 06 Mar 2003 06:26:23 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: "Stupid File Difference" function/module
Message-Id: <3E66EA05.2791F835@acm.org>
John Ramsden wrote:
>
> Is there an easy way, that works the same on Unix and Windows,
> of testing whether two files have identical contents?
>
> I'm not interested in what any differences are, and to
> streamline the code I'd rather not have to open the
> files myself. So Algorithm::Diff seems like overkill.
>
> I do realize this could be manually coded in a few lines;
> but this seems silly if there is a standard module and/or
> function.
perldoc File::Compare
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 06 Mar 2003 06:31:06 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: "Stupid File Difference" function/module
Message-Id: <slrnb6dqpb.1ir.mgjv@verbruggen.comdyn.com.au>
On 5 Mar 2003 07:53:32 -0800,
John Ramsden <john_ramsden@sagitta-ps.com> wrote:
> Is there an easy way, that works the same on Unix and Windows,
> of testing whether two files have identical contents?
File::Compare. It's a standard module, included in recent Perl
distributions.
Martien
--
|
Martien Verbruggen | That's not a lie, it's a terminological
Trading Post Australia | inexactitude.
|
------------------------------
Date: Thu, 06 Mar 2003 08:41:30 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Boolean statement which triggers on time
Message-Id: <3E66FBAA.8FE2D498@fujitsu-siemens.com>
Jan Fure wrote:
> =
> Hi;
> =
> I want to make a simple program which keeps track of which project I
> am working on.
> =
> The functionallity should be similar to a chess-clock, but with an
> arbitrary number of projects to which time can be allocated.
> =
> In case of computer crash or the application being intentionally or
> accidentally terminated, I need a log file which gets updated every
> minute.
> =
> I plan to use a tk radio button to keep track of which project is
> active.
Have a look at the "repeat" method. I have a "tail -f"-like Perl/Tk
script which creates a text widget and has it updated every 10 seconds:
--- start of code snippet
$t->repeat(10*1000, [\&update, $t, $src]);
=
MainLoop;
--- end of code snippet
I'd write out the button state to a file and make sure it gets synced
out to disk regularly enough. Haveing 1 line each minute gives a measely
60 lines an hour ...
HTH,
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Thu, 06 Mar 2003 06:22:49 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Can Perl can have the include head file like c?
Message-Id: <slrnb6dq9p.1ir.mgjv@verbruggen.comdyn.com.au>
[Please don't top-post.]
On 5 Mar 2003 06:01:31 -0800,
Clark Zhong <unixfighter@163.com> wrote:
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message news:<slrnb6av3v.1ir.mgjv@verbruggen.comdyn.com.au>...
>> On 4 Mar 2003 19:07:07 -0800,
>> Clark Zhong <unixfighter@163.com> wrote:
>> > Hai, can anyone help me?
>> > I want to include a config file in a main perl file, How can I do?
>> You should probably be more specific about what you want to achieve,
>> instead of assuming that you already know the emchanism by which you
>> would achieve it.
> It is my duty to say clearly about my project. This time I have
> coded a perl script to do some LDAP backup works, on TurboLinux,
> Perl 5.6. The code is all in one script file, and it works well. But
> the client want a .conf file for some reasons. May be he thought it
> can make the script more like linux program. so I must split some
> code from the original file to get a .conf file. That is what
> puzzle me. This my first Perl script, So I want to find some quick
> solution from c, such C head file.
In that case, maybe you should have a look at providing them with a
windows-stle ini file or something like that. There are modules
available on CPAN to do it. Otherwise, use a simple file with a format
like:
# start file
some_parameter = some value
other_parameter = other value
and process it with something like (untested)
my %config = (
some_parameter => "default_value",
other_parameter => "default_value",
more_params => "other defaults",
);
open CONFIG, "some_config_file" or die "Cannot open config file: $!";
while (my $line = <CONFIG>)
{
chomp;
next if $line =~ /^#/ or $line eq "";
my ($param, $value) = split /\s*=\s*/, $line;
die "Illegal parameter '$param'\n"
unless exists $config{$param};
$config{$param} = $value;
}
close CONFIG;
and from here onwards in the program, you use the $config{param}
values.
With do, you could include a program that sets perl variables
directly, but I wouldn't recommend that for this situation.
Martien
--
|
Martien Verbruggen | That's not a lie, it's a terminological
Trading Post Australia | inexactitude.
|
------------------------------
Date: Thu, 06 Mar 2003 00:29:23 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Counting matches in a regular expression
Message-Id: <3E66DCB3.AB4E5DA2@earthlink.net>
This is a multi-part message in MIME format.
--------------9736AD4ED458E1C45A321A7E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Anno Siegel wrote:
> Benjamin Goldberg wrote:
> > -=-=-=-=-=-
> >
> > Barty wrote:
> > [snip]
> > >
> > > It's running now.. Looks like it will take around two hours (on
> > > my athlon 1400) which is better than I though it would be! If
> > > anyone would like to play with it, here's my code:
> > > http://www.ianbishop.ca/649.zip
> >
> > I've attached my own code, and the output of one run.
> >
> > There couldn't *really* have only been 24 six-digit-combos which
> > didn't get at least 3 digits in common with a winning draw, could
> > there?
>
> I'm getting a lot more.
About how many more? (If you're getting 480 to my 24, then our problem
stems from counting differently -- I don't consider different
permutations of the same set of numbers to be different.)
Or, perhaps more relevant -- could you give me a "losing" number which
your program outputed and mine didn't?
> > And the whole thing finishes in 4 seconds -- is that possible?
>
> My run-time estimate: A bit above 5 hours.
>
> > If my algorithm is wrong, does anyone have a guess as to the
> > problem?
>
> I think the algorithm is correct, if it is meant to be this:
>
> 1. Generate the set of all three-element subsets of all recorded
> draws. (Each draw of six primarily generates 20 subsets of
> three, but of course many duplicates will appear across the
> draws.) Call these winners.
That's *almost* right -- for each recorded draw, I first sort the
numbers, before generating the 20 three-element subsets. Otherwise, the
numbers aren't in ascending order.
Oh, and I subtract 1 from each, so that the numbers go from 0..48,
instead of from 1..49.
Just FYI, I get 14339 elements in the "winners" set.
> 2. Build subsets of up to six elements of {1 .. 46} in sequence,
> adding one element at a time. At each step, check if any
> three-element subset of the current set is among the "winners"
> of step 1.
> If so, don't check any supersets of the current set.
> If we're in the last step (dealing with six-element subsets),
> print the set, again after checking that no subset of three is
> a "winner".
Actually, it's subsets of 0 .. 48, not 1..46, but that's otherwise
correct.
> > And if it's right -- nyah nyah, my code's faster than yours is :P
>
> Something must be wrong with your bit addressing scheme, is my guess.
I just added a bit of error checking to the reading-data-in part, and
discovered (part of) the problem. I had assumed that after the first
three fields ("649",1,"1982-06-12",) all the remaining fields were the
numbers drawn... from a mere glance at the data, this appeared to be so.
But on closer inspection, there are SEVEN, not SIX numbers on each line!
Looking at the OP's "severalregexp.pl" program shows that he simply uses
the first 6 of these numbers, ignoring the seventh.
Changing my code to likewise ignore the seventh number results in 16280
bits set in the $winners bitmask, and ZERO losing sets.
> The algorithm as such is sound, imo.
Thanks. Now all I have to do is figure out where what my code is doing,
is differing from the described algorithm.
I've attached my new-and-improved (but still not working) code.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
--------------9736AD4ED458E1C45A321A7E
Content-Type: application/x-perl;
name="bar.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="bar.pl"
use strict;
use warnings;
use integer;
print localtime() . " Marking winning combos.\n";
my $winners = "";
my @subsets;
for my $a ( 0 .. 3 ) { for my $b ( $a + 1 .. 4 ) {
push @subsets, [$a, $b, $_] for $b + 1 .. 5;
} }
sub idx {
$_[0] * 49 * 48 + $_[1] * 48 + $_[2];
}
open my $csv, '649.csv' or die "Cannot open 649.csv: $!";
while ( <$csv> ) {
# Discard ("649", row-id, date) from front.
my @d = (split /,/)[3..8];
@d == 6 or die "\@d == ".@d;
$_ >= 1 && $_ <= 49 or die $_ for @d;
--$_ for @d; # scale 1..49 down to 0..48
# sort into canonical order.
@d = sort {$a <=> $b} @d;
vec( $winners, idx(@d[@$_]), 1 ) = 1 for @subsets;
}
close $csv;
if( 1 ) {
my $count = 0;
$count += unpack('b*', $1) =~ tr/1//
while $winners =~ /([^\0]+)/g;
print localtime() . " $count winning combos marked.\n";
} else {
print localtime() . " Winning combos marked.\n";
}
# Generate some code.
my $losers = 0;
my $code = "";
for my $index ( 0 .. 5 ) {
my $p = $index - 1;
$code .= sprintf qq[for my \$i%s ( %s .. %d ) {\n],
$index, ($index ? "\$i$p + 1" : 0), 48 - 5 + $index;
$code .= join(" ||\n", map sprintf(
q[ vec( $winners, idx($i%d, $i%d, $i%d), 1 )],
@$_ ), grep $index == $_->[2], @subsets ) . " and next;\n"
if $index >= 2;
}
$code .= q{
print "$i0, $i1, $i2, $i3, $i4, $i5\n";
++$losers;
};
$code .= "}}}}}}\n";
print localtime() . " Printing losing combos.\n";
print $code;
eval "$code; 1" or die $@;
print localtime() . " There were $losers losers.\n";
__END__
--------------9736AD4ED458E1C45A321A7E--
------------------------------
Date: Thu, 06 Mar 2003 00:32:01 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: DBD and DBI on Solaris 64 bit
Message-Id: <3E66DD51.D40B70F@earthlink.net>
makbo wrote:
>
> Thanx for the suggestion. Profiling Perl is not something I've
> actually ever done before, because in over 10 years I've never needed
> to! ;-)
>
> My "perldoc -q profile" output recommends Devel::DProf or
> Benchmark.pm, any advice on which one to try?
I would use both.
First profile the code with Devel::DProf, and once you've found which
part needs to be sped up, think of various alternate ways to write it,
and use Benchmark to compare them.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Thu, 06 Mar 2003 06:46:59 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: file searching
Message-Id: <3E66EEDA.243F92FE@acm.org>
Ronald wrote:
>
> I have lots of files with a bunch of data in each file. I have to
> look for two sentances in each file and compare the numbers after the
> sentances. I dont know where to begin in writting the program to do
> this and i am tired of looking for anyhting about array of files and
> searching in them on the internet. Please help on this.
#!/usr/bin/perl
use warnings;
use strict;
use Cwd;
use File::Find;
find( sub {
return unless -T;
local( @ARGV, $_ ) = $File::Find::name;
my ( $num1, $num2 );
while ( <> ) {
($num1) = /This is sentence one. (\d+)/;
($num2) = /This is sentence two. (\d+)/;
if ( defined $num1 and defined $num2 ) {
# do something with the numbers
last;
}
}
}, $ARGV[0] || cwd );
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 06 Mar 2003 05:22:23 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Get directory only once and put it in array with File::Find
Message-Id: <jWA9a.81069$_J5.29217@nwrddc01.gnilink.net>
benrog wrote:
> I need an array that contains one element for each subdirectory found.
> My sub below doesn't do this of course, as @dirs will have an element
> for every $_ (file that's found). In other words, if Folder1 has 10
> files, my @dirs array will have Path/Folder1 10 times.
>
> I've thought of several possible hacks, but there has to be some
> graceful way to do this.
perldoc -f -X
and look for the "-d" test.
jue
------------------------------
Date: Thu, 06 Mar 2003 05:50:00 GMT
From: Steven Smolinski <steven.smolinski@sympatico.ca>
Subject: Re: Greedy regexps
Message-Id: <ckB9a.4727$KJ3.752778@news20.bellglobal.com>
Tad McClellan <tadmc@augustmail.com> wrote:
> Steven Smolinski <steven.smolinski@sympatico.ca> wrote:
>
>> I'm not very good at SGML applications,
>
> Yet you were disbelieving of the implicit claim made in my .sig ?
>
><just kidding>
No, Tad: I've had you scored up since [...checks scorefile...] mid-2000.
I just wanted to clarify the issue for myself.
But if I do find an error in one of your posts will you send me a bug
reward of $2.56 to frame? :-)
Steve
--
Steven Smolinski => http://arbiter.ca/
GnuPG Public Key => http://arbiter.ca/steves_public_key.txt
=> or email me with 'auto-key' in the subject.
Key Fingerprint => 08C8 6481 3A7B 2A1C 7C26 A5FC 1A1B 66AB F637 495D
------------------------------
Date: 5 Mar 2003 21:35:01 -0800
From: sade_bhat@yahoo.com (Sade Bhat Kalasabail)
Subject: Re: HELP- How can i use proxy service for port 80 as client using PERL
Message-Id: <3a621d3c.0303052135.510adda3@posting.google.com>
After lot of search and advice I am using soap(trying to). soaplite to
be precise. This uses the http protocol & port 80 as was requested. Am
getting 403 forbidden message dont know the reason why??
This is great, There are lot of people out there who are of immense
help. Good
work guys keep it up, I appreciate it a lot. Hope will be of help to
others
one day!!
Thanks
Sade
Abigail <abigail@abigail.nl> wrote in message news:<slrnb5tdtk.nh4.abigail@alexandra.abigail.nl>...
> Sade Bhat Kalasabail (sade_bhat@yahoo.com) wrote on MMMCDLXVII September
> MCMXCIII in <URL:news:3a621d3c.0302261651.44e185a3@posting.google.com>:
> ][ 'I have a client, that needs to contact a remote server on port
> ][ 80. Due to our firewall setup I am not allowed to do this
> ][ directly, but I can utilise a proxy service for port 80. How do I
> ][ do this, using perl?'
>
>
> How do you do what, using Perl? Write a proxy server? Install
> a proxy server? Start a proxy server? Connect to a proxy server?
>
> I wouldn't pick Perl for the first 3 tasks, and I may not pick
> Perl for the latter task either.
>
>
>
> Abigail
------------------------------
Date: 06 Mar 2003 06:48:03 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: HELP- How can i use proxy service for port 80 as client using PERL
Message-Id: <slrnb6drp3.7v4.abigail@alexandra.abigail.nl>
Sade Bhat Kalasabail (sade_bhat@yahoo.com) wrote on MMMCDLXXIV September
MCMXCIII in <URL:news:3a621d3c.0303052135.510adda3@posting.google.com>:
\\ After lot of search and advice I am using soap(trying to). soaplite to
\\ be precise. This uses the http protocol & port 80 as was requested. Am
\\ getting 403 forbidden message dont know the reason why??
Is this a question?
Abigail
--
$" = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_) {print "$_ $_{$_} "}};
%_ = (Just => another => Perl => Hacker); &{%_};
------------------------------
Date: Thu, 06 Mar 2003 00:40:18 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How can I write this regex?
Message-Id: <3E66DF42.E3A1B29C@earthlink.net>
Sara wrote:
>
> Occasionally I need to change patterns which are NOT preceeded (or
> followed, same difference) by certain other patterns. For example:
>
> replace "dog" with "canine" if dog is not preceeded by "cat " or
> "mouse ".
s/(?!<cat )(?!<mouse )dog/canine/g;
For "not followed by", the syntax is (?=stuff here).
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: 5 Mar 2003 21:28:43 -0800
From: sade_bhat@yahoo.com (Sade Bhat Kalasabail)
Subject: Re: How to access proxy server for Perl Soap client
Message-Id: <3a621d3c.0303052128.b88946c@posting.google.com>
Thanks chris,
I did change the proxy and used the user & pass env variables
$ENV{'HTTP_proxy_user'}="nsw\sade";
$ENV{'HTTP_proxy_pass'}="password";
use SOAP::Lite ;
print SOAP::Lite
-> uri("http://www.soaplite.com/Demo")
-> proxy("http://services.soaplite.com/hibye.cgi",
proxy => ["http" => "http://10.2.67.82/"])
-> hi()
-> result;
Now get the message
403 Forbidden ( The server denies the specified Uniform Resource Locator (URL).
Contact the server administrator. ) at ./hibye.pl line 16
What is 403 message, and how do I eliminate this too.
------------------------------
Date: Thu, 06 Mar 2003 06:15:09 GMT
From: James McIninch <james.mcininch@attbi.com>
Subject: Re: perl locks up my win98 computer
Message-Id: <NHB9a.378452$Ec4.380535@rwcrnsc52.ops.asp.att.net>
On Wednesday 05 March 2003 07:15 pm, Doglover posted to comp.lang.perl.misc:
> Hi. Does anyone know why Perl locks up my win98 machine when I do
> simple things like type PPM, or perldoc perldoc?
This is a feature of Microsoft Windows. It's one of the things that
differntiates it from other operating system products on the market.
> Can't even do
> control-alt-delete. It is totally locked. Simple "hello world" scripts
> run fine. Seems to be with both 5.6.1 and with 5.8.0, since I tried
> both. Strange, because 5.6 used to work. Then I tried 5.8, and started
> locking up. Uninstalled, and went back to 5.6, still locked up. So now
> I am back at 5.8.
>
> A google search revealed almost nothing.
--
---
SPAMMERS: please follow up to uce@ftc.gov
------------------------------
Date: Thu, 06 Mar 2003 06:24:26 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Perl Mysql uploading a image in a database.
Message-Id: <slrnb6dqcq.1ir.mgjv@verbruggen.comdyn.com.au>
On 5 Mar 2003 10:40:55 -0800,
niels <niels_bond@hotmail.com> wrote:
> Thanks for your advice.
Please, leave some context in next time.
> The execute_query I use to define the sort of method to use: DBI or
> mysql direct. It depends on the location where the script is.
>
> For now, i managed to save the image to the database. I don't get any
> errors any more. But moreover I show the images. Some images show
> themselves partly.
> I'm sure that the placeholders aren't set well. I think perl thinks
> that the end of the image is reached in the middle of the file.
Did you follow the advice on using binmode? Have you read up on
binmode to see why you should be using it? Are your database columns
wide enough to store all the data?
Martien
--
|
Martien Verbruggen |
Trading Post Australia | 42.6% of statistics is made up on the spot.
|
------------------------------
Date: Thu, 06 Mar 2003 06:22:13 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Print lines of file until certain string found?
Message-Id: <3E66E90B.854E13B8@acm.org>
"A. M. Schaer" wrote:
>
> What I am trying to do is have Perl open a file, print the lines of
> the file until it encounters a marker, <!--perl-->, then stop
> printing; however the code below doesn't do that; it just keeps
> printing the first line of the file over and over again; I know
> there's a flaw in my logic somewhere, but I just can't see it.
>
> Thanks.
>
> #!/usr/bin/perl
use warnings;
use strict;
> ###this doesnt do what I thought
> $file="calexample.html";
my $file = 'calexample.html';
> open (CURRFILE, $file) || die ("Cant open file");
open (CURRFILE, $file) || die ("Cant open $file: $!");
> $var='<!--perl-->';
my $var = qr/<!--perl-->/i;
> while ($line= <CURRFILE>) {
while ( my $line = <CURRFILE> ) {
> #!~ does not match
> #=~ matches
> until ($line =~/$var/i) {
> print $line;
> }
last if /$var/;
print;
> }
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 06 Mar 2003 06:56:17 +0000
From: Sharon Grant <peakpeek@purethought.com>
Subject: Re: Print lines of file until certain string found?
Message-Id: <5kqd6vk0dspqom3cu03mkhmg9ctqkhhfct@4ax.com>
On 5 Mar 2003 07:25:44 -0800, in comp.lang.perl.misc, mschaer@quantaservices.com (A. M. Schaer) wrote:
>What I am trying to do is have Perl open a file, print the lines of
>the file until it encounters a marker, <!--perl-->
>#!/usr/bin/perl
>###this doesnt do what I thought
>$file="calexample.html";
>open (CURRFILE, $file) ||
> die ("Cant open file");
>$var='<!--perl-->';
>
>while ($line= <CURRFILE>) {
>#!~ does not match
>#=~ matches
> until ($line =~/$var/i)
> {
>print $line;
>}
> }
I think you've mixed up your while and until. Easier to break out of
the loop using last ...
#!/usr/bin/perl -T
use warnings; use strict;
my $datadir = '/path/to/files';
my $file = "$datadir/calexample.html";
open (CURRFILE, $file) or die ("Cant open file");
my $var='<!--perl-->';
while (my $line = <CURRFILE>) {
last if $line =~ /$var/i;
print $line;
}
--
Sharon
------------------------------
Date: Thu, 06 Mar 2003 05:20:55 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: printing hash values
Message-Id: <XUA9a.81066$_J5.65460@nwrddc01.gnilink.net>
david wrote:
> If I have lexical values:
> my ($keyname, $keyvalue, $search, $replace);
> my %uid ();
>
> What would be the best way to print the contents of my hash once it
> has been populated? I am new to perl and am having a hard time
> visualizing the whole hash concept. Any suggestions?
A hash is (conceptually) the same thing as an array. The only difference is
that for an array you are limited to natural numbers as index while for a
hash you can use any string as the index.
Or you may say that the domain of an array are natural numbers while the
domain of a hash is text.
This is a bit simplified, but it should help you to understand the concept.
Now, as to your question: what do you consider to be the content of your
hash? The keys? Or the values? I.e. do you want to print all elements from
the domain or the codomain?
print keys(%uid);
print values(%uid);
jue
------------------------------
Date: Thu, 6 Mar 2003 01:04:02 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: printing hash values
Message-Id: <slrnb6dsn2.5np.tadmc@magna.augustmail.com>
david <dwlepage@yahoo.com> wrote:
> my %uid ();
>
> What would be the best way to print the contents of my hash once it
> has been populated?
print "$_ ==> $uid{$_}" for keys %uid;
or
print "$_ ==> $uid{$_}" for sort keys %uid;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 06 Mar 2003 08:01:12 +0000
From: Chris Lowth <dont@want.spam>
Subject: Re: printing hash values
Message-Id: <6gD9a.76$rB4.23651@newsfep1-win.server.ntli.net>
david wrote:
> If I have lexical values:
> my ($keyname, $keyvalue, $search, $replace);
> my %uid ();
>
> What would be the best way to print the contents of my hash once it
> has been populated? I am new to perl and am having a hard time
> visualizing the whole hash concept. Any suggestions?
> Thanks,
For "visualising" the hash contents (for debugging, checking etc) I use
"Data::Dumper". Use it like this..
use Data::Dumper;
my %uid = ( );
.. code to populate %uid ..
print Dumper( \%uid );
Chris
--
My real e-mail address is
chris at lowth dot sea-oh-em
------------------------------
Date: Thu, 06 Mar 2003 05:21:34 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Scripts in background
Message-Id: <yVA9a.81067$_J5.42996@nwrddc01.gnilink.net>
rsegovia wrote:
> I need a perl script which has to run 5 perl scripts in parallel. How
> can I do that?
perldoc -f fork
> Is it possible to handle the return codes of all of
> them?
perldoc -f wait
jue
------------------------------
Date: Thu, 06 Mar 2003 06:46:51 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: Scripts in background
Message-Id: <v9C9a.71203$ma2.19101068@twister.nyc.rr.com>
rsegovia <rafasegovia@yahoo.com> writes:
>
> I need a perl script which has to run 5 perl scripts in
> parallel. How can I do that?
With fork() and exec().
my %procs;
for my $script (@scripts) {
defined (my $pid = fork) or die "fork: $!";
if ($pid == 0) {
exec $script;
die "exec: $script: $!";
}
$procs{$pid} = $script;
}
But if you want to collect the std{out,err} of the five
scripts, you can just use IPC::Open3.
> Is it possible to handle the return codes of all of them?
With wait() or waitpid().
while ((my $pid = wait) != -1) {
my $exit = $? >> 8;
my $sig = $? & 127;
print "reaped: '$procs{$pid}' [$pid]\n",
" exit: $exit\n",
" sig : $sig\n";
}
Read all about those functions with:
$ perldoc -f fork
etc..
--
Steve
------------------------------
Date: Thu, 06 Mar 2003 07:15:55 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: tough regex problem
Message-Id: <LAC9a.71206$ma2.19118342@twister.nyc.rr.com>
Domenico Discepola <joeminga@yahoo.com> writes:
> A text file I've been presented with is described as follows:
>
> field seperator: \r\n\r\n\r\n\x07
> row seperator: \r\n\r\n\r\n\r\n
>
> I'm trying to replace the above field seperator with a single
> \x07 and the row seperator with a single \r\n
>
#!/usr/bin/perl -ln
use English;
BEGIN {
$RS = "\r\n\r\n\r\n\r\n";
$OFS = "\x07";
$ORS = "\r\n";
}
print split "\r\n\r\n\r\n\x07"
Check -a and -F, too. (I couldn't make -F take the "\07")
--
Steve
------------------------------
Date: Thu, 6 Mar 2003 01:01:44 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: tough regex problem
Message-Id: <slrnb6dsio.5np.tadmc@magna.augustmail.com>
Domenico Discepola <joeminga@yahoo.com> wrote:
> Subject: tough regex problem
You have a very simple regex problem. What have you tried?
> A text file I've been presented with is described as follows:
>
> field seperator: \r\n\r\n\r\n\x07
> row seperator: \r\n\r\n\r\n\r\n
>
> I'm trying to replace the above field seperator with a single \x07 and
> the row seperator with a single \r\n
The "hard" part of your problem must be getting the multiline
strings in the first place, I'm guessing.
perldoc -q match
"I'm having trouble matching over more than one line. What's wrong?"
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 06 Mar 2003 07:39:27 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: tough regex problem
Message-Id: <3e66f862.16241203@news.erols.com>
joeminga@yahoo.com (Domenico Discepola) wrote:
: A text file I've been presented with is described as follows:
:
: field seperator: \r\n\r\n\r\n\x07
: row seperator: \r\n\r\n\r\n\r\n
:
: I'm trying to replace the above field seperator with a single \x07 and
: the row seperator with a single \r\n
$/ = "\r\n\r\n\r\n\r\n"; # input record separator
$\ = "\r\n"; # output record separator
$ifs = "\r\n\r\n\r\n\x07"; # input field separator
$, = "\x07"; # output field separator
while( <> ) {
chomp;
print split /$ifs/;
}
------------------------------
Date: Thu, 06 Mar 2003 00:35:40 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: What is wrong with this piece of UDP server code?
Message-Id: <3E66DE2C.FDEDCCB4@earthlink.net>
Wei Weng wrote:
>
> I have the following simple code:
>
> #!/usr/bin/perl -w
>
> use IO::Socket;
>
> $port = 5050;
>
> $server = IO::Socket::INET->new(
> LocalPort => $port,
> Proto => "udp") ;
>
> die "Can not establish a UDP server listening on port $port\n"
> unless $server;
>
> print "sucessfully set up UDP server on port $port\n";
>
> # establish a UDP server, loop on accepting new connections
> while ($sock = $server->accept()) {
UDP is a connectionless protocol.
You cannot accept() a new connection with it.
A UDP server should have a loop for recv()ing data, and sending
responses to clients.
[snip]
> What did I do wrong?
You misunderstand the nature of the UDP protocol.
This is not inherently a perl problem.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Thu, 06 Mar 2003 15:48:08 +1000
From: "Andrew Rich" <andrew.rich@bigpond.com>
Subject: Re: What is wrong with this piece of UDP server code?
Message-Id: <6%A9a.61147$jM5.156880@newsfeeds.bigpond.com>
This works
#!/usr/bin/perl
use IO::Socket;
use IO::Socket::INET;
use Net::hostent;
my $port=shift || die "Usage server.pl <port>\n";
my $server = IO::Socket::INET->new( Proto => 'tcp',
LocalPort => $port,
Listen => SOMAXCONN,
Reuse => 1);
die "can't setup server" unless $server;
print "[Server $0 is running]\n";
while ($client = $server->accept())
{
$client->autoflush(1);
while ( <$client>)
{
print ;
}
close $client;
}
------------------------------
Date: 6 Mar 2003 05:35:41 GMT
From: Wei Weng <wweng@play.cs.columbia.edu>
Subject: Re: What is wrong with this piece of UDP server code?
Message-Id: <b46mnd$f8t$1@tornado.cs.columbia.edu>
Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> Wei Weng wrote:
>>
>> I have the following simple code:
>>
>> #!/usr/bin/perl -w
>>
>> use IO::Socket;
>>
>> $port = 5050;
>>
>> $server = IO::Socket::INET->new(
>> LocalPort => $port,
>> Proto => "udp") ;
>>
>> die "Can not establish a UDP server listening on port $port\n"
>> unless $server;
>>
>> print "sucessfully set up UDP server on port $port\n";
>>
>> # establish a UDP server, loop on accepting new connections
>> while ($sock = $server->accept()) {
> UDP is a connectionless protocol.
> You cannot accept() a new connection with it.
> A UDP server should have a loop for recv()ing data, and sending
> responses to clients.
> [snip]
>> What did I do wrong?
Ah, I see. Thanks for pointing that out. :)
Now, how do I easily code something to receive a line of data from $server?
The only thing I can come up with is something like:
my $msg;
while ($server->recv($next_byte, 1)) {
if ($next_byte ne "\n") {
$msg .= $next_byte;
} else {
$msg .= $next_byte;
print ("A line: $msg");
$msg = "";
}
}
Undoubtedly, it is very ugly. I suspect there must be some other perl way to
make this look elegant. :)
Thanks
Wei
------------------------------
Date: 6 Mar 2003 05:51:16 GMT
From: Wei Weng <wweng@play.cs.columbia.edu>
Subject: Re: What is wrong with this piece of UDP server code?
Message-Id: <b46nkk$fsf$1@tornado.cs.columbia.edu>
Andrew Rich <andrew.rich@bigpond.com> wrote:
> This works
> #!/usr/bin/perl
> use IO::Socket;
> use IO::Socket::INET;
> use Net::hostent;
> my $port=shift || die "Usage server.pl <port>\n";
> my $server = IO::Socket::INET->new( Proto => 'tcp',
> LocalPort => $port,
> Listen => SOMAXCONN,
> Reuse => 1);
> die "can't setup server" unless $server;
> print "[Server $0 is running]\n";
> while ($client = $server->accept())
> {
> $client->autoflush(1);
> while ( <$client>)
> {
> print ;
> }
> close $client;
> }
But this is a TCP server, not a UDP one.
Wei
------------------------------
Date: Thu, 06 Mar 2003 06:33:36 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: What is wrong with this piece of UDP server code?
Message-Id: <slrnb6dqu0.1ir.mgjv@verbruggen.comdyn.com.au>
On Thu, 06 Mar 2003 15:48:08 +1000,
Andrew Rich <andrew.rich@bigpond.com> wrote:
> This works
Repeat of subject:
Subject: Re: What is wrong with this piece of UDP server code?
^^^
Your code:
> my $server = IO::Socket::INET->new( Proto => 'tcp',
^^^^^^^^^^^^^^
Martien
--
|
Martien Verbruggen | Useful Statistic: 75% of the people make up
Trading Post Australia | 3/4 of the population.
|
------------------------------
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 4671
***************************************