[22815] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5036 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun May 25 06:05:48 2003

Date: Sun, 25 May 2003 03:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 25 May 2003     Volume: 10 Number: 5036

Today's topics:
        Capturing comport/serial data on Windows (via Realterm) (simon)
        Determining if an element exists in an array (newguy)
    Re: Determining if an element exists in an array <laocoon@fastmail.fm>
    Re: Determining if an element exists in an array <laocoon@fastmail.fm>
    Re: Determining if an element exists in an array <abigail@abigail.nl>
        Help: How do I make a graph with this module? (entropy123)
        How do I tell if an element of an array exists? (newguy)
        HTML Template => Arrays (Ikky Sleepy)
    Re: HTML Template => Arrays <noreply@gunnar.cc>
    Re: HTML Template => Arrays (Ikky Sleepy)
    Re: Lookahead: find empty line(s) or $ <w.koenig@acm.org>
    Re: Paths relative to a module <res1uzbe@verizon.net>
        Perl Nightmare on OS X (Nick)
        permissions mnemonic <ericw@nospam.ku.edu>
    Re: permissions mnemonic <uri@stemsystems.com>
        problem with IO::Handle <burch@burcarpat.com>
    Re: problem with IO::Handle <burch@burcarpat.com>
    Re: Using GD::Graph in a CGI <null@null.com>
    Re: Using GD::Graph in a CGI <null@null.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 24 May 2003 19:40:09 -0700
From: 623402@despammed.com (simon)
Subject: Capturing comport/serial data on Windows (via Realterm)
Message-Id: <7a8b3e34.0305241840.69200aec@posting.google.com>

Hi All,
Thanks to a user, there is an example of using the free Realterm
program from Perl to capature data from a serial port on windows,
something that can be problematic

http://realterm.sourceforge.net/realterm_from_perl.html

Simon


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

Date: 24 May 2003 16:17:08 -0700
From: mcquade2@yahoo.com (newguy)
Subject: Determining if an element exists in an array
Message-Id: <289d131d.0305241517.7e680e77@posting.google.com>

Hello 

I have two arrays:

@array1 = { 10.1.0.1, 10.0.1.2, 10.1.0.3, 10.1.0.12, 10.1.0.14 };
@array2 = { 10.1.0.1, 10.1.0.24 };

foreach element (@array2) {
  # How do I check to see if element exists in @array1 without
  # matching on other elements?  For example, the first iteration
  # of this loop would have element set to 10.1.0.1
  # but I do not want to match on 10.1.0.12 and 10.1.0.14
}

Thoughts?


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

Date: Sun, 25 May 2003 01:24:29 +0200
From: Lao Coon <laocoon@fastmail.fm>
Subject: Re: Determining if an element exists in an array
Message-Id: <Xns9386E6BFEFD7laocoon@62.153.159.134>

Lao Coon <laocoon@fastmail.fm> wrote in news:Xns9386E27F8469laocoon@
62.153.159.134:

> mcquade2@yahoo.com (newguy) wrote in news:289d131d.0305241517.7e680e77
> @posting.google.com:
> 
>> Hello 
>> 
>> I have two arrays:
>> 
>> @array1 = { 10.1.0.1, 10.0.1.2, 10.1.0.3, 10.1.0.12, 10.1.0.14 };
>> @array2 = { 10.1.0.1, 10.1.0.24 };
>> 
>> foreach element (@array2) {
>>   # How do I check to see if element exists in @array1 without
>>   # matching on other elements?  For example, the first iteration
>>   # of this loop would have element set to 10.1.0.1
>>   # but I do not want to match on 10.1.0.12 and 10.1.0.14
>> }
>> 
>> Thoughts?
> 
> perldoc -q certain element

+ perldoc -f last

HTH
Lao


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

Date: Sun, 25 May 2003 01:22:54 +0200
From: Lao Coon <laocoon@fastmail.fm>
Subject: Re: Determining if an element exists in an array
Message-Id: <Xns9386E27F8469laocoon@62.153.159.134>

mcquade2@yahoo.com (newguy) wrote in news:289d131d.0305241517.7e680e77
@posting.google.com:

> Hello 
> 
> I have two arrays:
> 
> @array1 = { 10.1.0.1, 10.0.1.2, 10.1.0.3, 10.1.0.12, 10.1.0.14 };
> @array2 = { 10.1.0.1, 10.1.0.24 };
> 
> foreach element (@array2) {
>   # How do I check to see if element exists in @array1 without
>   # matching on other elements?  For example, the first iteration
>   # of this loop would have element set to 10.1.0.1
>   # but I do not want to match on 10.1.0.12 and 10.1.0.14
> }
> 
> Thoughts?

perldoc -q certain element


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

Date: 25 May 2003 00:37:21 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Determining if an element exists in an array
Message-Id: <slrnbd0421.kuj.abigail@alexandra.abigail.nl>

newguy (mcquade2@yahoo.com) wrote on MMMDLIII September MCMXCIII in
<URL:news:289d131d.0305241517.7e680e77@posting.google.com>:
}}  Hello 
}}  
}}  I have two arrays:
}}  
}}  @array1 = { 10.1.0.1, 10.0.1.2, 10.1.0.3, 10.1.0.12, 10.1.0.14 };

That create a one element array, the element being a reference to a hash.
The hash is odd, because it has an odd number of elements in the construction
list - Perl will add a value of 'undef' for the key 10.1.0.14.
Now, the strings you give as keys and values are strange as well.
They are four character strings, all starting with a carriage return.

Perhaps you wanted:

    @array1 = ('10.1.0.1', '10.0.1.2', '10.1.0.3', '10.1.0.12', '10.1.0.14');

?

}}  @array2 = { 10.1.0.1, 10.1.0.24 };
}}  
}}  foreach element (@array2) {
}}    # How do I check to see if element exists in @array1 without
}}    # matching on other elements?  For example, the first iteration
}}    # of this loop would have element set to 10.1.0.1
}}    # but I do not want to match on 10.1.0.12 and 10.1.0.14
}}  }
}}  
}}  Thoughts?


This is a faq. Read it. "man perlfaq"


Abigail
-- 
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
         / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
         % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
         BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'


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

Date: 24 May 2003 16:55:23 -0700
From: email_entropy123@yahoo.com (entropy123)
Subject: Help: How do I make a graph with this module?
Message-Id: <90cdce37.0305241555.446a0598@posting.google.com>

Hey all,

Any advice on how to use the Graph::Base module? I can't seem to get
started creating verticies, edges, etc...

The code starts like this:

package Graph::Base
use vars qw(@ISA);
require Exporter;
@ISA = qw(Exporter);

# new
# 
# $G=Graph->new(@V)
#
#
sub new {
my $class = shift;
my $G= { };
bless $G, $class;
$G->add_verticies(@_) if @_;
return $G;
)

What kind of argument do I send to this thing? I have a list of
'verticies' say
a-b, b-c, c-d, c-e and so on but have no idea how to send them to this
subroutine/module.

When I perldoc -q ISA or Exporter nothing comes up....

Thanks!

entropy


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

Date: 25 May 2003 02:58:45 -0700
From: mcquade2@yahoo.com (newguy)
Subject: How do I tell if an element of an array exists?
Message-Id: <289d131d.0305250158.2db4f75d@posting.google.com>

Hello Folks, 

Given that I have two arrays with the following defined:

@a1 = ( 10.1.0.1, 10.1.0.2, 10.1.0.3, 10.1.0.14, 10.1.0.10 );
@a2 = ( 10.1.0.1, 10.1.0.2 );

How can I tell if an element in @a2 exists in @a1? 

Thanks


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

Date: 24 May 2003 16:10:32 -0700
From: ikkysleepy@yahoo.com (Ikky Sleepy)
Subject: HTML Template => Arrays
Message-Id: <362106a5.0305241510.344dc37b@posting.google.com>

I have a perl problem, and I looked for this on google but I coulnd't
find anything usefull. I have a html page, the page has 3/4 different
sections: Heading, BODY, and Ending. I want my perl script to grab
that html file: guest.html and seperate the 3/4 sections and put them
into 3/4 arrays. I can read the html page, just i'm having problem
seperating the 3/4 sections into 3 arrays. Anything would be usefull.

# guest.html
######################
<html>
<head>
<title> TEST </title>
</head>
|TEMPLATE|
<body>
|TEMPLATE|
blah 
|TEMPLATE|
blah
|TEMPLATE|
</body>
</html>
######################

I am trying to seperate them 3 or 4 parts of the HTML file, not but
not by html syntax but by a
Line of Text "|TEMPLATE|" in the html after each section. So after
finding |TEMPLATE| the script should create another array like so

$html_template[0]  = "HTML of HEADING";
$html_template[1]  = "HTML of blah";
$html_template[2]  = "HTML of blah"; 
$html_template[3]  = "HTML of ENDING"; 


print @html_template; 

# so this output would be 
######################
<html>
<head>
<title> TEST </title>
</head>
<body>

blah 

blah

</body>
</html>
######################


# I read the file into an array but when I search for |TEMPLATE|, line
be line, and try to make  the lines of text from the begining to the
|TEMPLATE| I get an empty array or a script that never ends. 
 
# the purpose is to have a template without using cgi so that I can
just change the html file and get a new Theme.


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

Date: Sun, 25 May 2003 02:39:15 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: HTML Template => Arrays
Message-Id: <bap3nn$23lu7$1@ID-184292.news.dfncis.de>

Ikky Sleepy wrote:
> I have a perl problem, and I looked for this on google but I
> coulnd't find anything usefull. I have a html page, the page has
> 3/4 different sections: Heading, BODY, and Ending. I want my perl
> script to grab that html file: guest.html and seperate the 3/4
> sections and put them into 3/4 arrays.

<snip>

> # I read the file into an array but when I search for |TEMPLATE|,
> line be line, and try to make  the lines of text from the begining
> to the |TEMPLATE| I get an empty array or a script that never ends.

Would you mind posting the program you have right now? I have
difficulties to understand what it is you want to do, and some Perl
code - even if it doesn't yet give you the wanted result - may be
helpful.

/ Gunnar

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



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

Date: 25 May 2003 02:57:13 -0700
From: ikkysleepy@yahoo.com (Ikky Sleepy)
Subject: Re: HTML Template => Arrays
Message-Id: <362106a5.0305250157.78ec236d@posting.google.com>

I figured it out thx anyways, here is what I did

# guest.html
#################################################
<html>
<head>
<title> TEST </title>
</head>
TEMPLATE
<body>
TEMPLATE
blah 
TEMPLATE
 blah
TEMPLATE
</body>
</html>
#################################################


# ikky.pl
#################################################

#!/usr/bin/perl

# Print the header
print "Content-type: text/html\n\n";

# Read the template to an array
open(FILE,"guest.html") or dienice("Couldn't open $file for reading: $! \n");
flock(FILE,1);seek(FILE,0,0);
@html_template = <FILE>;
$html_lines = @html_template;
close (FILE);

# Set temp variables to 0
$temp_[$_] = $_ = $i = 0;
foreach $line (@html_template)
 {

   # Set temp array
   $temp[$_] = $line;

   # Find and replace TEMPLATE
   if($line =~ /TEMPLATE/)
     {$line =~ s/TEMPLATE//; chomp($line); $i++;}

   # Add new line to previous line in an array
   $section[$i] .= $line;

    $_++;
  

  }

print $section[0];
print $section[1];
print $section[2];
print $section[3];
print $section[4];

exit(0);
#################################################

it worked => http://javascripting.hypermart.net/cgi-bin/beta/ikky.pl


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

Date: Sun, 25 May 2003 01:17:45 +0200
From: Winfried Koenig <w.koenig@acm.org>
Subject: Re: Lookahead: find empty line(s) or $
Message-Id: <3ECFFD99.7020004@acm.org>

Martin Schweikert wrote:
> Hi!
> 
> I would like to find empty lines or '$' characters in a lookahead 
> expression. Finding empty lines or a '$' character in separate 
> expressions is easy:
> 
> (?=\n{2,}) finds one or more empty lines
> (?=\$)     finds a '$' character
> 
> This works so far.
> 
> But now I want to say: "find one or more empty line or a '$' character" 
> in one statement.
> 
> I tried variants of
> 
> (?=[\n{2,}\$])       '$' is found correctly, but introducing the [] 
> causes \n{2,} to match a single \n instead of 2 or more.
> 
> (?=\n{2,})(?=\$)     finds nothing at all; the expression (?=)(?=) I have 
> seen in some example code does not work for me, it seems.
> 
> (?=\n{2,}|\$)        finds the empty line, but not the '$' character
> 
> ((?=\n{2,})|(?=\$))  same as previous
> 
> 
> In case that the content matters, I'm using this piece of code:
> 
> ----------
> use strict;
> undef $/;
> open (TEXT, 'foo.txt');
> while (<TEXT>) {
>     while ( /\$(\d+)\/(\d+)\$(.*?)(<expression wanted>)/gs ) {
> 	print "$1-$2: $3\n";
>     }    
> }
> ----------
> 
> The input looks like
> 
> ----------
> asdasdf
> 
> $1/11$ aaa aaaaaaaa aaa a aaaaaaaa aa $1/12$ bbbbbbb bb bbbbbbb b bbb bb
> 
> $1/13$ cccccc ccccc cc c 
> ccccccccc cc $1/14$ dddddddd dddddd dddd
> dddddddd ddddd
> ----------
> 
> What I would like to see is:
> 
> ----------
> 1-11: aaa aaaaaaaa aaa a aaaaaaaa aa
> 1-12: bbbbbbb bb bbbbbbb b bbb bb
> 1-13: cccccc ccccc cc c ccccccccc cc
> 1-14: dddddddd dddddd dddddddddddd ddddd
> ----------
you don't need any lookahead. Try this:

use strict;
undef $/;
open(TEXT, 'foo.txt') or die "could not open 'foo.txt'  $!";
$_ = <TEXT>;
while (m!\$(\d+)/(\d+)\$([^\$\n]*(?:\n[^\$\n]+)*)!gs) {
     my($l, $r, $v) = ($1, $2, $3);
     $v =~ s/\s+/ /g;
     $v =~ s/^ //;
     $v =~ s/ $//;
     print "$l-$r: $v\n";
}

Winfried Koenig



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

Date: Sun, 25 May 2003 08:13:27 GMT
From: emcee <res1uzbe@verizon.net>
Subject: Re: Paths relative to a module
Message-Id: <HW_za.7798$8i4.4840@nwrddc02.gnilink.net>

Benjamin Goldberg wrote:
> It can be, depending on your server software, but the CGI specification
> does not require that this be possible.
> 

I know that current directory isn't always the location of the script, 
but that's not really an issue in this case.

> Actually, $INC{'module'} should probably contain the path you passed to
> lib.pm, followed by "/module".

Well, than I just must be doing something wrong. Here's a simple example 
of what I've tried:

testinc.pm contents:
print $INC{'testinc.pm'}

test.pl contents:
use testinc

I put them both in the same directory, than run them with the current 
directory as there location and I get this result:

testinc.pm

which, of course, doesn't really help.


> 
> Then it's a good thing that File::Spec is a standard module, isn't it?
> 

Well, I read through the pod on File::Spec and came up with this:

$_=File::Spec->rel2abs($INC{'testinc.pm'});
s/testinc\.pm$//;

It works but, there seems to be a different version of this method for 
each OS, so I'm not sure if it will work for all operating systems.

I'll likely end up using File::Spec, but I would like to find a simpler 
answer, one that doesn't require loading a seperate module. When the 
problem first first came up, my first though was to use %INC because I 
remembered using it in the past for this same type of problem, when it 
didn't work, I thought it was because of use lib, but even with out that 
I seem to have the same problem. The only other thing that's changed it 
that I switched from Perl 5.6 to 5.8, but I doubt that's it.



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

Date: 24 May 2003 22:31:25 -0700
From: nick@tiger-marmalade.com (Nick)
Subject: Perl Nightmare on OS X
Message-Id: <6a6938d0.0305242131.3a8ec6bf@posting.google.com>

I'm a new to Perl and OS X, but I recently tried to install Perl 5.8.0
on my iMac for the primary reason that I wasn't able to download
anything from CPAN without it trying to install Perl 5.8.0 as well. I
followed the directions posted at
http://developer.apple.com/internet/macosx/perl.html, configuring
things to use apple's perl 5.6.0 setup as closely as possible (i.e.
install prefix of /usr),   I've been getting undefined symbol errors
ever since. I moved libperl.dylib to a new file libperlold.dylib in
/System/Library/Perl/darwin/CORE and reissuing make install, but to no
avail). I then tried removing any and all .bundle files I could find
in /Library/Perl and rerunning make install, also to no avail. So now
I'm dead in the water and fresh out of ideas. Like I said, I'm new to
Perl and to OS X, so I'm a little worried -- Is this likely to cause
any problems with my system overall (don't many OS X apps rely on perl
to some extent?). Is there a way to fix this? Please be gentle . . .


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

Date: Sun, 25 May 2003 04:59:53 GMT
From: Eric Wilhelm <ericw@nospam.ku.edu>
Subject: permissions mnemonic
Message-Id: <pan.2003.05.24.23.56.12.956046.13926@nospam.ku.edu>

foreach $r (0,r) {
  foreach $w (0,w) {
    foreach $x (0,x) {
	$h=($r||"-").($w||"-").($x||"-");
	print "$h -> ",($r&&1).($w&&1).($x&&1),
		" -> ",($r&&1)*4+($w&&1)*2+($x&&1),"\n";
	}
    }
  }

Lots of fun with the short-circuit operators and it even does something
useful.

I imagine it can be "golfed" down a bit but I'll leave that to the crazy
cryptographers here:)

--Eric


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

Date: Sun, 25 May 2003 05:58:40 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: permissions mnemonic
Message-Id: <x7ptm7tvn3.fsf@mail.sysarch.com>

>>>>> "EW" == Eric Wilhelm <ericw@nospam.ku.edu> writes:

  EW> foreach $r (0,r) {
  EW>   foreach $w (0,w) {
  EW>     foreach $x (0,x) {
  EW> 	    $h=($r||"-").($w||"-").($x||"-");
  EW> 	    print "$h -> ",($r&&1).($w&&1).($x&&1),
  EW> 		" -> ",($r&&1)*4+($w&&1)*2+($x&&1),"\n";
  EW> 	  }
  EW>   }
  EW> }

  EW> I imagine it can be "golfed" down a bit but I'll leave that to the crazy
  EW> cryptographers here:)

rather i would make it run under strict and warnings. and

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: Sat, 24 May 2003 22:26:25 -0700
From: "Burc Arpat" <burch@burcarpat.com>
Subject: problem with IO::Handle
Message-Id: <bapk62$com$1@news.Stanford.EDU>


hi,

i have a wrapper around standard i/o, basically providing methods like
log(), warning(), error() which allows me to say error("some message"), etc.
internally, this class uses the IO::Handle module.  there is a stream
variable defined as $stream = new IO::Handle and then set to STDOUT, STDERR
or a file depending on user's choice.

the problem is, sometimes, i want the output to be sent to a file but also
to STDOUT at the same time.  the code for this looks like below:

    $self->stream()->print($message);
    $self->stream()->flush();

    if ($self->force_stdout()) {
      $FORCED_STDOUT->print($message);
      $FORCED_STDOUT->flush();
    };

where $FORCED_STDOUT is defined like this at the begining of the module:

    my $FORCED_STDOUT = new IO::Handle;
    $FORCED_STDOUT->fdopen(fileno(STDOUT), "w");

funny enough, the call to $FORCED_STDOUT->print() *always* prints the
message to the file instead of STDOUT no matter what.  i tried using
IO::Handle's sync(), perl's select() but nothing mattered.  am i doing
something wrong here?

bests,

burch




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

Date: Sat, 24 May 2003 23:36:59 -0700
From: "Burc Arpat" <burch@burcarpat.com>
Subject: Re: problem with IO::Handle
Message-Id: <bapoaf$e7l$1@news.Stanford.EDU>

never mind.  stupid mistake on my part...

burch




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

Date: Sun, 25 May 2003 03:21:19 +0200
From: "Fernando" <null@null.com>
Subject: Re: Using GD::Graph in a CGI
Message-Id: <bap5qe$fdm$1@news.ya.com>

> You can force the browser to hit the server and not get local cache by
> using an HTML meta tag, I forget which one tho... are you using IE?
> See if you get the same results in Mozilla
>
> w i l l

Yes, that works
The exact tag is:
<META HTTP-EQUIV= "pragma" CONTENT="no-cache">

Thanks






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

Date: Sun, 25 May 2003 03:27:49 +0200
From: "Fernando" <null@null.com>
Subject: Re: Using GD::Graph in a CGI
Message-Id: <bap66j$frg$1@news.ya.com>

> Try this example program and see how it fares for you.  If it works,
> you can follow after it:
>
>
> use CGI qw(:standard);
> use GD;
> if(param('image')){
> print "Content-type: image/png\n\n";
> binmode STDOUT;
> $im = new GD::Image(100,100);
> $lightpurple=$im->colorAllocate(255,200,255);
> $black=$im->colorAllocate(0,0,0);
> $im->interlaced('true');
> $im->line(param('n1'),param('n2'),param('n3'),
> param('n4'),$black);
> print $im->png;
> exit;
> }
> print header,
> start_html('GD Example'),
> h1('GD Example'),
> start_form,
> textfield('n1'),p,
> textfield('n2'),p,
> textfield('n3'),p,
> textfield('n4'),p,
> "Enter four numbers from 0 to 100 and submit",p,
> submit,
> end_form,
> hr;
> if(param()){
> print img{src=>'GDtest.pl?n1='.param('n1').
> '&n2='.param('n2').'&n3='.param('n3').
> '&n4='.param('n4').'&image=yes',width=>100,height=>100};
> }
> print end_html;

Yeah!
It works out-of-the-box!

In fact, this is very similar to what i was intending to do.

Thank you very much!


Fernando
Madrid, Spain







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

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


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