[18199] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 367 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 27 14:05:58 2001

Date: Tue, 27 Feb 2001 11:05:23 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <983300722-v10-i367@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 27 Feb 2001     Volume: 10 Number: 367

Today's topics:
        "Offset outside string" errors in syswrite - <K.H.Pennemann@Informatik.Uni-Oldenburg.DE>
    Re: "Offset outside string" errors in syswrite - <ren@tivoli.com>
    Re: Creating string of values ignoring empty values <joe+usenet@sunstarsys.com>
    Re: Creating string of values ignoring empty values (Tad McClellan)
    Re: Creating string of values ignoring empty values (Tad McClellan)
    Re: Creating string of values ignoring empty values <ren@tivoli.com>
    Re: Etymology of hash <lmoran@wtsg.com>
    Re: FAQ 4.73:   How do I verify a credit card checksum? <callgirl@la.znet.com>
    Re: form/cgi help really needed! (Afkamm)
    Re: HELP needed on a simple Parse::RecDescent program ( <terrence.brannon@oracle.com>
        How are SOL_SOCKET and SO_REUSEADDR defined in various  (Kenny McCormack)
    Re: How are SOL_SOCKET and SO_REUSEADDR defined in vari (Casper H.S. Dik - Network Security Engineer)
    Re: How the CLPM turns (Peter J. Acklam)
    Re: How the CLPM turns <callgirl@la.znet.com>
    Re: How the CLPM turns <mothra@nowhereatall.com>
        if $line =~ /ref\d+/ <kmojar@bmjgroup.com>
    Re: if $line =~ /ref\d+/ (Rafael Garcia-Suarez)
    Re: if $line =~ /ref\d+/ <peb@bms.umist.ac.uk>
    Re: if $line =~ /ref\d+/ (Tad McClellan)
    Re: if $line =~ /ref\d+/ nobull@mail.com
        libnet and Net::SMTP config.pm is wrong <alan1.pettigrew1@fox1-europe1.com>
        Newbie - HTML Mail <stiroff@elsitech.com>
    Re: obtaining keys from values - hashes (Abigail)
    Re: obtaining keys from values - hashes <gnari@astrologyis.com>
    Re: obtaining keys from values - hashes nobull@mail.com
    Re: obtaining keys from values - hashes (John Joseph Trammell)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 27 Feb 2001 17:33:40 +0100
From: "Karl-Heinz Pennemann" <K.H.Pennemann@Informatik.Uni-Oldenburg.DE>
Subject: "Offset outside string" errors in syswrite -
Message-Id: <97gkul$46i@news.Informatik.Uni-Oldenburg.DE>

Hi!

Look at the little program, which follows. My question is: Why does the
error occur in line 10? Yes I know, the offset is outside the buffer,
but why doesn't the error occur in line 7? Because the amount of data
to copy (called LENGTH in the docs, but not to confuse with
length($buffer)) is zero?? It's zero in line 10, too!?


use IO::File;                                     # 1
my $handle = new IO::File;                        # 2
sysopen ($handle, "test.txt", O_WRONLY | O_CREAT);# 3
binmode ($handle);                                # 4
my $buffer0 = "";                                 # 5
my $buffer1 = "1";                                # 6
syswrite($handle, $buffer0, 0, 0);                # 7
syswrite($handle, $buffer0, 3, 0);                # 8
syswrite($handle, $buffer1, 1, 0);                # 9
syswrite($handle, $buffer1, 0, 1);                #10
die;                                              #11

I think, the only error should occur in line 8, so is this a bug?
I don't know, how the syswrite function is implemented (look at pp_sys.c
- I didn't understand it ;-/, but in Perl I would implement syswrite
as follows:

# SNOPSIS: syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
sub syswrite {
  my ($handle, $buffer, $amount, $offset) = @_;
  # test handle, buffer and offset
  if ($amount==0) {return 0;}                  # Nothing to do (line 7, 10)
  else {
    if ($offset+$amount>=length($buffer)) {
      die "Offset outside string";             # line 8
    }
    else {
      # write data...                          # line 9
    }
  }
}


thanks
Karl-Heinz


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

Date: 27 Feb 2001 11:03:43 -0600
From: Ren Maddox <ren@tivoli.com>
Subject: Re: "Offset outside string" errors in syswrite -
Message-Id: <m3y9usjbww.fsf@dhcp9-175.support.tivoli.com>

On Tue, 27 Feb 2001, K.H.Pennemann@Informatik.Uni-Oldenburg.DE wrote:

> Look at the little program, which follows. My question is: Why does
> the error occur in line 10? Yes I know, the offset is outside the
> buffer, but why doesn't the error occur in line 7? Because the
> amount of data to copy (called LENGTH in the docs, but not to
> confuse with length($buffer)) is zero?? It's zero in line 10, too!?

Implementation aside, this is straight out of the docs for syswrite:

               An OFFSET may be specified to write the data from
               some part of the string other than the beginning.
               A negative OFFSET specifies writing that many
               bytes counting backwards from the end of the
               string.  In the case the SCALAR is empty you can
               use OFFSET but only zero offset.

Note the last sentence.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 27 Feb 2001 11:31:51 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Creating string of values ignoring empty values
Message-Id: <m3k86c2iko.fsf@mumonkan.sunstarsys.com>

twolfmaier@acm.org (Thomas Wolfmaier) writes:

> foreach (qw(hasSection1AccessPermission hasSection2AccessPermission
> hasSection3AccessPermission)) {
>     $access_permissions .= ($access_permissions ? ', ' : '') .
> ACCESS_PERMISSION->{$_}->{$lang} if $record->{$_};
> }
> 
> 
> I don't particularly like this last part. I tried to use 'join' together
> with 'map':
> 
> my $access_permission = join ', ', map { ACCESS_PERMISSION->{$_}->{$lang} }
> qw(hasSection1AccessPermission hasSection2AccessPermission
> hasSection3AccessPermission);

Are you sure? You don't do any %record-checking here.
> 
> For some reason I find this more readable. Unfortunately, it gives me:
> 
> Section 1, , Section 3
> 
> According to the documentation it is possible to return zero elements from
> a map block, but I have no idea how and I could not find any example in the
> documentation.

map evaluates the BLOCK in a list context, so one way to return zero
elements is to return the empty list () (see perldata for details).  
Otherwise you could use grep instead:

    print join ", ",  map {$_ or ()} ( 0, "a", "", "c" );
    print join ", ",  grep {$_} ( 0, "a", "", "c" );

This will drop all list elements that are false in boolean context (0, "",
and undef).  In your case, I think you want something like

  $access_permission = join ', ', 
       map { $record->{$_} ? ACCESS_PERMISSION->{$_}->{$lang} : () } qw ...

or

  $access_permission = join ', ', map { ACCESS_PERMISSION->{$_}->{$lang} }
      grep { $record->{$_} } qw ...


Alternately, you might consider just building a single access array at the
beginning of script

  my @access = map { ACCESS_PERMISSION->{$_}->{$lang} } qw ...

and then do a 

  join ', ', grep { $record->{$_} } @access

on a per-record basis.

HTH

Joe Schaefer
-- 
#include <stdio.h> /* requires gcc and *nix
use strict; system("cc -x c $0") and die $?; open C, "|a.out" or die $! . q*/
main(){char s[32]; remove("a.out"); printf("%s/C hacker\n",fgets(s,32,stdin));
return 0;}/*; print C "Just another Perl"; close C or die $?; #*/


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

Date: Tue, 27 Feb 2001 10:53:32 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Creating string of values ignoring empty values
Message-Id: <slrn99njbs.ae6.tadmc@tadmc26.august.net>

Thomas Wolfmaier <twolfmaier@acm.org> wrote:
>I am looking for a better, in the sense of shorter and more readable, way
>to accomplish the following:
>
>My script retrieves a record as a hash reference from a database. Let's
>assume the record represents a user and includes fields for different types
>of permissions, e.g.,
>
>hasSection1AccessPermission
>hasSection2AccessPermission
>hasSection3AccessPermission
>
>The values are 0 for false and 1 for true. I now have to create a
>comma-separated string of a user's access permissions in English or German.

>That's the way I came up with:

>use constant ACCESS_PERMISSION {
>    'hasSection1AccessPermission' => {
>        'en' => 'Section 1',
>        'de' => 'Bereich 1'
>    },



>I tried to use 'join' together
>with 'map':


I think this does it:

   my $access_permissions = join ', ',
      map ACCESS_PERMISSION->{$_}{$lang},
      grep $record->{$_}, sort keys %{&ACCESS_PERMISSION};


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


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

Date: Tue, 27 Feb 2001 10:55:23 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Creating string of values ignoring empty values
Message-Id: <slrn99njfb.ae6.tadmc@tadmc26.august.net>

Thomas Wolfmaier <twolfmaier@acm.org> wrote:

>my $record = {} ; // given, hash reference of record retrieved from database
                   ^^
                   ^^
>my $lang = 'en'; // given, either 'en' or 'de'
                  ^^
                  ^^

It is important to keep in mind which language it is that you
are writing in  :-)


>
>use constant ACCESS_PERMISSION {
                              ^^^
                              ^^^

You seem to be missing a comma there.


>    'hasSection1AccessPermission' => {
>        'en' => 'Section 1',
>        'de' => 'Bereich 1'
>    },
>    'hasSection2AccessPermission' => {
>        'en' => 'Section 2',
>        'de' => 'Bereich 2'
>    },
>    'hasSection3AccessPermission' => {
>        'en' => 'Section 3',
>        'de' => 'Bereich 3'
>    }
>};


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


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

Date: 27 Feb 2001 10:57:20 -0600
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Creating string of values ignoring empty values
Message-Id: <m33dd0kqrz.fsf@dhcp9-175.support.tivoli.com>

On 27 Feb 2001, twolfmaier@acm.org wrote:

> my $access_permission = join ', ', map {
> ACCESS_PERMISSION->{$_}->{$lang} } qw(hasSection1AccessPermission
> hasSection2AccessPermission hasSection3AccessPermission);
> 
> For some reason I find this more readable. Unfortunately, it gives
> me:
> 
> Section 1, , Section 3

After fixing a couple of minor errors (needed a "=>" for that constant
declaration, and "//" is not a Perl comment indicator), I was unable
to reproduce your problem.  Of course, the code given includes all
three sections, but even after removing section two, I still get
correct output.

Actually, the only way I was able to get your output was by including
a typo in the list of permissions.  You can get around this --
presuming you want to be able to ignore permissions that are not in
your ACCESS_PERMISSION hash -- by adding "|| ()" to the code for the
map.  This causes any value not in the hash to return an empty list
instead, and empty lists get squeezed out as always.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Tue, 27 Feb 2001 13:49:37 -0500
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: Etymology of hash
Message-Id: <1ktn9tk2qa7uh3caja819tpbiiaa7rid0d@4ax.com>

On 27 Feb 2001 15:56:53 GMT, abigail@foad.org (Abigail) wrote
wonderful things about sparkplugs:


>Mapping (in LPC)

See now that makes sense to me.  I know exactly what that's going to
do.  I have no idea what LPC is, however.

>
>
>Abigail


--
"> thanks in advance !!!
If you are going to do anything 'in advance' it should be RTFM."
       --swiped from a nobull clp.misc post

Lou Moran <lmoran@wtsg.com>


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

Date: Tue, 27 Feb 2001 08:47:16 -0800
From: Kiralynne Schilitubi <callgirl@la.znet.com>
Subject: Re: FAQ 4.73:   How do I verify a credit card checksum?
Message-Id: <3A9BDA14.2A3A125C@la.znet.com>

Sam Holden wrote:
 

> Kiralynne Schilitubi wrote:
> >PerlFAQ Server wrote:

> >>   How do I verify a credit card checksum?

> >>     Get the Business::CreditCard module from CPAN.


> >Coding for this can be accomplished in just under
> >fifty lines of code, even less if obfuscated, and
> >it is very simple code.
 
> The module does what the question asks in signifacantly less than
> fifty lines of very readable non-obfuscated code. Maybe you should
> take a look and find out why it would take you so much more code.


Your statements are most false. I have a copy of this module
and I have studied it extensively. You are simply lying.

Your remaining comments are dismissed as suspect.

Godzilla!


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

Date: Tue, 27 Feb 2001 18:11:17 GMT
From: afkamm@bigfoot.com (Afkamm)
Subject: Re: form/cgi help really needed!
Message-Id: <Xns9055B8D658232afkfoot@194.117.133.134>

On the 27 Feb 2001 in comp.lang.perl.misc,  wrote the following in a
hurry. 

>The solution is probably a simple one...
>
>But the question remains: How can I send the info on a line ONLY if
>the checkbox at the end of the line is checked?? 

Have you thought about about adding another section to your perl 
script, its only function is to check whether the checkbox is ticked or 
not.

ie. Main part of script displays form, form gets submitted and the 
input values get sent to another part of the script that checks for a 
ticked checkbox. If box is ticked do this with data, else do that.

The script is going to play with the data anyway, so just make it do a 
check before it does so.

Is that of any use?

Marc :-)

PS. Your question was easier to understand in alt.html.tags :-)



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

Date: Tue, 27 Feb 2001 09:32:29 -0800
From: Terrence Monroe Brannon <terrence.brannon@oracle.com>
Subject: Re: HELP needed on a simple Parse::RecDescent program (problem: some  rules are matched twice)
Message-Id: <3A9BE4AD.34563117@oracle.com>

I think Parse::RecDescent has a LEFTOP directive to facilitate this parsing
idiom.

Gwyn Judd wrote:

> I was shocked! How could Randal L. Schwartz <merlyn@stonehenge.com>
> say such a terrible thing:
> >>>>>> "Eric" == Eric Liao <ekliao@hotmail.com> writes:
> >
> >Eric> I am a new user of Parse::RecDescent.  I tried to use v1.80 to
> >Eric> implement a simple parser with a simple grammar for parsing c/c++/java
> >Eric> code.  The result looks good except that 5 rules seem to be matched
> >Eric> twice (see output and expected output below).  I could not figure out
> >Eric> why.  Any help would be greatly appreciated.  Please e-mail
> >Eric> ekliao@hotmail.com or post to the groups.  Thank you.
> >
> >You can't print out your result while you are parsing it, because you
> >can't "unprint" a backtrack.  You backtracked in "expression" from the
> >first subrule to the second subrule, but you'd already printed out the
> >result of a successful first step of that first subrule.
> >
> >Don't do that. Pass the data upstairs, and have the final top-level
> >rule do all the work.
>
> Alternatively, you could make the grammar LL(1) so there is no need for
> backtracking. There is only the one problematic non-terminal so it
> shouldn't be too hard. Simply replace this:
>
> expression      :       unary_expr PLUS_OP expression
>                         |       unary_expr
>
> with this:
>
> expression      :       unary_expr plus_expression
>
> plus_expression :       PLUS_OP expression
>                         |       # nothing
>
> --
> Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
> Fortune's real live weird band names #13:
>
> Alien Sex Fiend

--
Terrence Brannon
Oracle Corporation
500 Oracle Parkway
M/S 3op1556a
Redwood Shores, CA 94065
(650) 607-5482




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

Date: 27 Feb 2001 11:21:51 -0600
From: gazelle@yin.interaccess.com (Kenny McCormack)
Subject: How are SOL_SOCKET and SO_REUSEADDR defined in various flavors of Unix?
Message-Id: <97gnnf$5v5$1@yin.interaccess.com>

This question arose in the context of a Perl program, but my real purpose is
to find out how much variation there is in Unix flavors other than Linux and
Solaris (which are the [only] two I have access to at the moment).

I have the following line in a Perl program:

    die $! unless setsockopt(S,$SOL_SOCKET,$SO_REUSEADDR,pack("l",1));

and this depends on having SOL_SOCKET and SO_REUSEADDR defined.  Now, I know
that there are "officially correct" ways of doing this in Perl, that depend
on having the full Perl installation online.  But I cannot use those
methods, because of the old/standard "Can I expect my clients to have the
development environment installed?" question, to which the answer has to be
"No."  All I can rely on is that they have the Perl executable.

Under Linux, I have found:

% egrep 'SOL_SOCKET|REUSEA' /usr/include/*/*.h
/usr/include/asm/socket.h:#define SOL_SOCKET    1
/usr/include/asm/socket.h:#define SO_REUSEADDR  2

and under Solaris:

% egrep 'SOL_SOCKET|REUSEA' /usr/include/*/*.h
/usr/include/sys/socket.h:#define       SO_REUSEADDR    0x0004
/usr/include/sys/socket.h:#define       SOL_SOCKET      0xffff

Now, where this is all coming from is that in the past, I've found that
Solaris seems to do things differently than most other Unixes.  So, I've
done this:

    $SOCK_STREAM = $ENV{'OSTYPE'} =~ /solaris/ ? 2 : 1;

and it seems to work.  My question is directed at those with experience in
Unixes other than Linux and Solaris, in regards to SOL_SOCKET and
SO_REUSEADDR.  What values do these take on in other Unix OS's?

I'm also interested in any Perl solutions that do not involve external
files.  If there is a way to get it inside of a Perl program, that would be
good.


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

Date: 27 Feb 2001 18:59:25 GMT
From: Casper.Dik@Holland.Sun.Com (Casper H.S. Dik - Network Security Engineer)
Subject: Re: How are SOL_SOCKET and SO_REUSEADDR defined in various flavors of Unix?
Message-Id: <97gted$k53$1@new-usenet.uk.sun.com>

[[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]

gazelle@yin.interaccess.com (Kenny McCormack) writes:

>Under Linux, I have found:

>% egrep 'SOL_SOCKET|REUSEA' /usr/include/*/*.h
>/usr/include/asm/socket.h:#define SOL_SOCKET    1
>/usr/include/asm/socket.h:#define SO_REUSEADDR  2

>and under Solaris:

>% egrep 'SOL_SOCKET|REUSEA' /usr/include/*/*.h
>/usr/include/sys/socket.h:#define       SO_REUSEADDR    0x0004
>/usr/include/sys/socket.h:#define       SOL_SOCKET      0xffff



You shouldn't care about that.

if you use a modern version of perl, you simply use "use Socket" and
import the properly set variables that way.

If you hardcode a few possible values now, you can be sure you code
breaks in future.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.


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

Date: 27 Feb 2001 17:19:23 +0100
From: jacklam@math.uio.no (Peter J. Acklam)
Subject: Re: How the CLPM turns
Message-Id: <wkelwk6s36.fsf@math.uio.no>

merlyn@stonehenge.com (Randal L. Schwartz) writes:

>         IF YOU WANT TO GET YOUR NAME IN PRINT, please send me column
>         ideas.  Please.  Please.

You are not doing the dance.

Peter

(that was a reference to Calvin & Hobbes for those of you
who didn't get it... :-) )

-- 
Peter J. Acklam - jacklam@math.uio.no - http://www.math.uio.no/~jacklam


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

Date: Tue, 27 Feb 2001 08:51:31 -0800
From: Kiralynne Schilitubi <callgirl@la.znet.com>
Subject: Re: How the CLPM turns
Message-Id: <3A9BDB13.32E1E180@la.znet.com>

Bernard El-Hagin wrote:

> After frequenting this newsgroup for over 2 years I've come to know
> some of the regular posters here and decided that, as a service to
> newbies, I'd write up some typical regular poster replies to typical
> newbie questions. That way someone new to the group can pick the style
> of answer he/she prefers and look for that person in the future.
 
> DISCLAIMER!

> My goal in doing this is not to offend anyone. Quite the contrary,
> actually.
 
Rather funny! I enjoyed a good laugh reading your article,
you pig!

Godzilla!


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

Date: Tue, 27 Feb 2001 10:00:29 -0800
From: mothra <mothra@nowhereatall.com>
Subject: Re: How the CLPM turns
Message-Id: <3A9BEB3D.7C656DBD@nowhereatall.com>

"Randal L. Schwartz" wrote:
[snipped]
> 
> And there's another 2.5 a month (how do I keep up, gah!)... so once
> again...
> 
>         IF YOU WANT TO GET YOUR NAME IN PRINT, please send me column
>         ideas.  Please.  Please.

How about:

How to extract MIME encoded e-mail
How to spell check a textform field 


> Past columns are at:
> 
>         http://www.stonehenge.com/merlyn/WebTechniques/
>         http://www.stonehenge.com/merlyn/UnixReview/
>         http://www.stonehenge.com/merlyn/LinuxMag/
> 
> for examples of what not to send me because I already did them. :)
> 

Mothra!


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

Date: Tue, 27 Feb 2001 16:31:10 +0000
From: Kourosh A Mojar <kmojar@bmjgroup.com>
Subject: if $line =~ /ref\d+/
Message-Id: <3A9BD64E.7CEC739D@bmjgroup.com>

dear all,

im a novice perl user (win32) trying to achieve what might be simple
task that has got me baffled. im basically using if statements to handle
line by line expressions of an inputted text file. for example (in
brief):

open(INPUT, $input);
open(OUTPUT, $output);
@lines_in = <INPUT>;
close (INPUT);
foreach $line_in ( @lines_in ) {
	if ( $line_in =~ /ID="REF(\d+)"/ ) {
		$ref_temp = $1;
		print "$ref_temp\n";
		}
	print OUTPUT "$line_in";
	}
close (OUTPUT);

i use this sort of syntax all the time. although $line_in will have more
than one occurrence of /ID="REF(\d+)"/ for which i would like to print
the value for each one.

any help or a point in the right direction would be greatly appreciated.
thanking you in advance and for your kind attention,

kourosh a mojar


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

Date: Tue, 27 Feb 2001 16:54:34 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: if $line =~ /ref\d+/
Message-Id: <slrn99nmtj.tmr.rgarciasuarez@rafael.kazibao.net>

Kourosh A Mojar wrote in comp.lang.perl.misc:
> 
> im a novice perl user (win32) trying to achieve what might be simple
> task that has got me baffled. im basically using if statements to handle
> line by line expressions of an inputted text file. for example (in
> brief):
> 
> open(INPUT, $input);
> open(OUTPUT, $output);

You should really add an "or die" error-handling clause after your
open() calls if this program will ever be used to do something
important.

> @lines_in = <INPUT>;
> close (INPUT);
> foreach $line_in ( @lines_in ) {
> 	if ( $line_in =~ /ID="REF(\d+)"/ ) {
> 		$ref_temp = $1;
> 		print "$ref_temp\n";
> 		}
> 	print OUTPUT "$line_in";
> 	}
> close (OUTPUT);
> 
> i use this sort of syntax all the time. although $line_in will have more
> than one occurrence of /ID="REF(\d+)"/ for which i would like to print
> the value for each one.

Use the /g modifier ("global match"), described in the perlop section of
the docs. The little program below demonstrates this technique :

#!/usr/local/bin/perl
while (<DATA>) {
  @matches = /ID="REF(\d+)"/g;
  print "Matches : @matches\n";
}
__DATA__
ID="REF01"
ID="REF2" ID="REF003"

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


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

Date: Tue, 27 Feb 2001 17:24:49 +0000
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: if $line =~ /ref\d+/
Message-Id: <3A9BE2E1.86560C8A@bms.umist.ac.uk>

Kourosh A Mojar wrote:

> im a novice perl user (win32) trying to achieve what might be simple
> task that has got me baffled. im basically using if statements to handle
> line by line expressions of an inputted text file. for example (in
> brief):
> 
> open(INPUT, $input);
> open(OUTPUT, $output);
> @lines_in = <INPUT>;
> close (INPUT);
> foreach $line_in ( @lines_in ) {
>         if ( $line_in =~ /ID="REF(\d+)"/ ) {
>                 $ref_temp = $1;
>                 print "$ref_temp\n";
>                 }
>         print OUTPUT "$line_in";
>         }
> close (OUTPUT);
> 
> i use this sort of syntax all the time. although $line_in will have more
> than one occurrence of /ID="REF(\d+)"/ for which i would like to print
> the value for each one.

It is unnecessary to read the whole file into memory.
It is much more efficient to iterate through the file using a while
loop.

e.g.
	open(INPUT, $input) or die "can't open the input file : $!";
	while(<INPUT>){
		while(/ID="REF(\d+)"/g){
			print "The number is $1\n";
		}
	}

the second while loop in this snippet of code iterates through all
occurrences of the test string on the input line.

so if the input file looks like this :-

ID="REF1" ID="REF2" ID="REF3"
ID="REF4" ID="REF5" ID="REF6"

the output should look like :-

The number is 2
The number is 3
The number is 4
The number is 5
the number is 6

HTH

Paul


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

Date: Tue, 27 Feb 2001 17:28:47 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: if $line =~ /ref\d+/
Message-Id: <slrn99nlpo.akm.tadmc@tadmc26.august.net>

Kourosh A Mojar <kmojar@bmjgroup.com> wrote:

>foreach $line_in ( @lines_in ) {
>	if ( $line_in =~ /ID="REF(\d+)"/ ) {


   while ( $line_in =~ /ID="REF(\d+)"/g ) {
   ^^^^^                              ^


>although $line_in will have more
>than one occurrence of /ID="REF(\d+)"/ for which i would like to print
>the value for each one.


Use a while() and a 'g' option (perldoc perlop).


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


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

Date: 27 Feb 2001 17:48:56 +0000
From: nobull@mail.com
Subject: Re: if $line =~ /ref\d+/
Message-Id: <u9lmqsow3b.fsf@wcl-l.bham.ac.uk>

Kourosh A Mojar <kmojar@bmjgroup.com> writes:

> im a novice perl user

Then ditch all the bad habits NOW!  I won't insult your intelegence by
telling you what bad habits I'm talking about - they are the ones we
tell _all_ newbies to ditch.  Don't bitch just ditch them.  In the long
run you'll be better off.

> 	if ( $line_in =~ /ID="REF(\d+)"/ ) {

> i use this sort of syntax all the time. although $line_in will have more
> than one occurrence of /ID="REF(\d+)"/ for which i would like to print
> the value for each one.

 	while ( $line_in =~ /ID="REF(\d+)"/g ) {

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 27 Feb 2001 16:36:15 GMT
From: Alan Pettigrew <alan1.pettigrew1@fox1-europe1.com>
Subject: libnet and Net::SMTP config.pm is wrong
Message-Id: <VA.0000000f.01c20157@fox-europe.com>

I have just installed libnet (1.06) with PPM on 2 NT machines.

On one I went through the configuration at the end and filled in an 
SMTP host name.  All other fields I took the default (blank, usually). 
On the other machine I didn't configure it.

Both machines said that there was already a configuration and did I 
want to change it, although both were fresh installs.

In both cases at the end of perl\site\lib\Net\config.pm were lines of:
# WARNING ...
# Below this line is auto-generated, *ANY* changes will be lost

On the second (not configured) there was nothing after these lines.  On 
the first machine there was:
DATA&gt%NetConfig = (
   ftp_int_passive => '0',
   ...
);

Not surprisingly, the DATA&gt caused an error when I tried using the 
module.

On a 3rd machine which had been configured by someone else the lines 
were:
%NetConfig = (
   ftp_int_passive => '0',
   ...
);

which worked.

I amended my config.pm and all is well, but I would like to know if I 
did something wrong in the configuration, or whether there is a bug in 
the installation.

I did repeat the installation with all defaults for the configuration 
and got exactly the same problem.

Can anyone shed some light on this?

Alan
The 1s are there to stop the spam.




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

Date: Tue, 27 Feb 2001 12:48:37 -0600
From: "Sharon Weis" <stiroff@elsitech.com>
Subject: Newbie - HTML Mail
Message-Id: <52908DF6309A16EC.79F8B9A4B2051CB9.C6BCDEF176CD1024@lp.airnews.net>

Hi,  I am new to Perl CGI and I am trying to send mail in HTML format. I am
using ActivePerl and installed the MIME::Lite package. I am able to send
mail successfully. However, it is printing the following errors on my CGI
form. I have never modified, let alone opened the Config.pm or the
Domain.pm. I've noticed that 3 out of 4 errors have to do with the domain.
Am I suppose to modify these files and if so what am I suppose to modify?

Errors:
Use of uninitialized value in concatenation (.) at
E:/Perl/site/lib/Net/Config.pm line 44. Use of uninitialized value in scalar
assignment at E:/Perl/site/lib/Net/Domain.pm line 204. Use of uninitialized
value in scalar assignment at E:/Perl/site/lib/Net/Domain.pm line 204. Use
of uninitialized value in pattern match (m//) at
E:/Perl/site/lib/Net/Domain.pm line 228. Use of uninitialized value in split
at E:/Perl/site/lib/Net/Domain.pm line 235.
I've included the code in which the errors point:

Config.pm
--------------------------------------------------------
if ($< == $> and !$CONFIGURE)  {
    my $home = eval { (getpwuid($>))[7] } || $ENV{HOME};
    $file = $home . "/.libnetrc";    #line 44
    $ref = eval { do $file } if -f $file;
    %NetConfig = (%NetConfig, %{ $ref })
 if ref($ref) eq 'HASH';
}

Domain.pm
----------------------------------------------------------------------------
-------
    # Look for environment variable

    $domain ||= $ENV{LOCALDOMAIN} ||= $ENV{DOMAIN} || undef;  #line 204

    if(defined $domain) {
     $domain =~ s/[\r\n\0]+//g;
     $domain =~ s/(\A\.+|\.+\Z)//g;
     $domain =~ s/\.\.+/\./g;
    }


Domain.pm
----------------------------------------------------------------------------
-------
sub domainname {

    return $fqdn
     if(defined $fqdn);

    _hostname();
    _hostdomain();

    # Assumption: If the host name does not contain a period
    # and the domain name does, then assume that they are correct
    # this helps to eliminate calls to gethostbyname, and therefore
    # eleminate DNS lookups

    return $fqdn = $host . "." . $domain     #line 228
 if($host !~ /\./ && $domain =~ /\./);

    # For hosts that have no name, just an IP address
    return $fqdn = $host if $host =~ /^\d+(\.\d+){3}$/;

    my @host   = split(/\./, $host);
    my @domain = split(/\./, $domain);     #line 235
    my @fqdn   = ();

    # Determine from @host & @domain the FQDN

    my @d = @domain;


Thanks,

Sheri








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

Date: 27 Feb 2001 16:08:52 GMT
From: abigail@foad.org (Abigail)
Subject: Re: obtaining keys from values - hashes
Message-Id: <slrn99nk8k.jh7.abigail@tsathoggua.rlyeh.net>

richard dobson (rdobson@MailAndNews.com) wrote on MMDCCXXXVII September
MCMXCIII in <URL:news:3AAE6756@MailAndNews.com>:
;; Basic question, but, does anyone know a quick way of obtaining a hash key if 
;; I 
;; know the value?


You life with the false assumption that hashes describe invertible
mappings. They don't.


Abigail
-- 
print 74.117.115.116.32.97.110.111.116.104.101.114.
      32.80.101.114.108.32.72.97.99.107.101.114.10;


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

Date: Tue, 27 Feb 2001 17:10:31 +0000
From: Ragnar Hafstaš <gnari@astrologyis.com>
Subject: Re: obtaining keys from values - hashes
Message-Id: <983294085.1152950535@news.virgin.net>

On Tue, 27 Feb 2001, Abigail wrote:
>richard dobson (rdobson@MailAndNews.com) wrote on MMDCCXXXVII September
>MCMXCIII in <URL:news:3AAE6756@MailAndNews.com>:
>;; Basic question, but, does anyone know a quick way of obtaining a hash key if 
>;; I 
>;; know the value?
>
>
>You life with the false assumption that hashes describe invertible
>mappings. They don't.
>

If, however, you are sure that your particular hash is invertible, then
the good old
%inverted=reverse %original 
might be what you want

gnari



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

Date: 27 Feb 2001 17:44:30 +0000
From: nobull@mail.com
Subject: Re: obtaining keys from values - hashes
Message-Id: <u9ofvoowap.fsf@wcl-l.bham.ac.uk>

richard dobson <rdobson@MailAndNews.com> writes:

[snip FAQ: "How do I look up a hash element by value?" ]

> Thanks in advance

If you are going to do anything in advance of posting it should be
to check the FAQ.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 27 Feb 2001 18:05:33 GMT
From: trammell@bayazid.hypersloth.net (John Joseph Trammell)
Subject: Re: obtaining keys from values - hashes
Message-Id: <slrn99noto.tes.trammell@bayazid.hypersloth.net>

On Tue, 27 Feb 2001 09:41:38 -0500, richard dobson wrote:
> Basic question, but, does anyone know a quick way of
> obtaining a hash key if I know the value?

If all your values are unique, this works:

    my %rev = reverse %hash;
    print "$rev{$value}";

If they aren't, you're toast.



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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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

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

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


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


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