[28288] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9652 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 27 11:05:39 2006

Date: Sun, 27 Aug 2006 08: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, 27 Aug 2006     Volume: 10 Number: 9652

Today's topics:
        Beginner: read $array with line breaks line by line <mstep@t-online.de>
    Re: Beginner: read $array with line breaks line by line <hjp-usenet2@hjp.at>
    Re: Beginner: read $array with line breaks line by line <bik.mido@tiscalinet.it>
    Re: Catalog() in Win32::ODBC for MySQL <rvtol+news@isolution.nl>
    Re: Match regular expression from LEFT to right <fritz-bayer@web.de>
    Re: Match regular expression from LEFT to right robic0
    Re: Perl's GUI <zentara@highstream.net>
    Re: Perl's GUI <zentara@highstream.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 27 Aug 2006 15:40:50 +0200
From: Marek Stepanek <mstep@t-online.de>
Subject: Beginner: read $array with line breaks line by line
Message-Id: <C1176D82.2B3F7%mstep@t-online.de>


Hello happy Perlers,


my aim is to transform a large Address list in html to a LaTeX-Address-List
for a series (?) letter (=the same letter with many different addresses).

My html-address-list you may find on following internet address:

http://podiuminternational.org/addresses/competitions/competitionsfunds.htm

This file I am reading in without line breaks, or say I read in the whole
file as one line (I understand this like that, I am beginner), setting $/ to
undef. First I am reading in the file, removing the html; result is the
array @complete_address. The next step is to transform these entries of
@complete_address into a LaTeX File of the form:

\addrentry
    {Lastname}
    {Firstname}
    {Address}
    {Telephone}
    {F1 } = m (ännlich) w (eiblich) u (zwitter oder unbekannt)
    {F2 } = Firma
    {F3 } = email
    {F4 } = Kommentar
    {KEY} = Schlüssel

I find these LaTeX-entries far too short - if somebody has an Perl-solution
for a series letter in LaTeX, I would really appreciate a hint! So this part
is my question, and it is still in work. Problem is: @complete_address
contains variables, with different lines, which I would like to read in line
by line. So I set $/ = "\n"; but this seems not to work.

And a construct of 

foreach my $addr (@competitions)
  { $/ = "\n";
    while (<$addr>)
      {
       ...
      }
  }

seems not valid Perl.


Thank you for your patience


marek


Here my script so far:


#! /usr/bin/perl

use strict;
use warnings;
use HTML::Entities;

$/ = undef;

my (@competitions, @complete_address);

while (<>)
  {
    foreach my $entry (m"<dd>(.+?)</dd>"g)
      {
        push (@complete_address, $entry);
      }
  }
    
foreach my $e (@complete_address)
  {
    $e =~ s!<span\s+class="comp2">([^<]+)</span>!"Competition: " . $1 .
"\n\n"!ge;
    $e =~ s!<br />!\n!g;
    $e =~ s!<[^>]+>!!g;
    push (@competitions, $e);
  }

my $out_file1 = 'letter_comp_addr_01.adr';
open OUT1, "> $out_file1" or die "Connot create your out_file: $!";
my $out_file2 = 'letter_comp_addr_02.adr';
open OUT2, ">> $out_file2" or die "Connot create your out_file: $!";

my ($competition, $email, $first_name, $last_name, $gender);
foreach my $addr (@competitions)
  {
    $/ = "\n";
    ($competition) = $addr =~ m"^Competition:\s+(.+)";
    $addr =~ s/^(International|National) Competition\s*$//i; # not working
    ($gender, $first_name, $last_name) = $addr =~
/^(Mr\.?|Mrs\.?)?([A-Z][a-z]+(?:\s+[A-Z][a-z]+\.?)?)\s+([A-Z][a-z]+)\s*$/;
    # not working either
    if ($gender)
      {
        if ($gender eq m/Mrs\.?/ )
          {
            $gender = "w";
          }
          elsif ($gender eq m/Mr\.?/ )
          {
            $gender = "m";
          }
          elsif ($gender == 'undef' )
          {
            $gender = "u";
          }
        }
    ($email) = $addr =~ m"((&#\d+;)+)";
    $email = decode_entities($email) if $email;
    
  }

print OUT1 join ("\n\n", @competitions);
print OUT1 "\n\n";
print OUT2 "\\addrentry\n";
print OUT2 "\t{$first_name}\n" if $first_name;
print OUT2 "\t{$last_name}\n" if $last_name;
print OUT2 "\t{$competition}\n";
print OUT2 "\t{$gender}\n" if $gender;
print OUT2 "\t{$email}\n" if $email;

close OUT1;
close OUT2;



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

Date: Sun, 27 Aug 2006 16:15:23 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Beginner: read $array with line breaks line by line
Message-Id: <slrnef3a7t.86f.hjp-usenet2@yoyo.hjp.at>

On 2006-08-27 13:40, Marek Stepanek <mstep@t-online.de> wrote:
> Problem is: @complete_address contains variables, with different
> lines, which I would like to read in line by line. So I set $/ = "\n";
> but this seems not to work.
>
> And a construct of 
>
> foreach my $addr (@competitions)
>   { $/ = "\n";
>     while (<$addr>)
>       {
>        ...
>       }
>   }
>
> seems not valid Perl.

The <> operator reads from a file handle, not a string. You probably
want to use the split function here:

foreach my $addr (@competitions)
  { 
    foreach (split(/\n/, $addr)
      {
       ...
      }
  }


	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: 27 Aug 2006 16:35:00 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Beginner: read $array with line breaks line by line
Message-Id: <5fa3f2l3f0s6rq411k8jnocih6tmcis1fu@4ax.com>

On Sun, 27 Aug 2006 15:40:50 +0200, Marek Stepanek <mstep@t-online.de>
wrote:

>is my question, and it is still in work. Problem is: @complete_address
>contains variables, with different lines, which I would like to read in line
>by line. So I set $/ = "\n"; but this seems not to work.

$/ affects reading from a filehandle. But the entries of
@complete_address are plain strings, so I don't know what you're
doing, but I don't think you are reading from a filehandle to process
them, hence setting $/ won't do anything (useful).

>And a construct of 
>
>foreach my $addr (@competitions)
>  { $/ = "\n";
>    while (<$addr>)
>      {
>       ...
>      }
>  }
>
>seems not valid Perl.

Indeed, see above! For completeness I must say that there's a "trick"
to actually do what you want:


  foreach my $addr (@competitions) { 
      open my $fh, '<', \$addr or die "D'Oh! $!\n";
      local $/ = "\n";
      while (<$fh>) {
  	  # ...
      }
  }


BUT BEFORE I GET CHASTISED FOR POINTING YOU TO THIS "SOLUTION", let me
tell you that you DON'T want to do so. You most probably want to
split() on \n, instead.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 27 Aug 2006 14:44:03 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Catalog() in Win32::ODBC for MySQL
Message-Id: <ecsbc3.d0.1@news.isolution.nl>

dmittleider@gmail.com schreef:
> I'm trying to pull

Don't multipost. Please read the Posting Guidelines, that are posted
here twice a week.

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: 27 Aug 2006 01:49:39 -0700
From: "fritz-bayer@web.de" <fritz-bayer@web.de>
Subject: Re: Match regular expression from LEFT to right
Message-Id: <1156668579.175680.43690@75g2000cwc.googlegroups.com>


anno4000@radom.zrz.tu-berlin.de wrote:
> fritz-bayer@web.de <fritz-bayer@web.de> wrote in comp.lang.perl.misc:
> > anno4000@radom.zrz.tu-berlin.de wrote:
> > > fritz-bayer@web.de <fritz-bayer@web.de> wrote in comp.lang.perl.misc:
> > > > anno4000@radom.zrz.tu-berlin.de wrote:
> > > > > fritz-bayer@web.de <fritz-bayer@web.de> wrote in comp.lang.perl.misc:
>
> [...]
>
> > So let me explain this words - as I did below. I'm trying to capture a
> > group of radio buttons which resides inside a table in the middle of a
> > html document, which contains lots of tags and text.
> >
> > Capturing the back of the html table after the radio buttons is easy as
> > a ".*?</table>, will do the job. However, capturing the first <table>
> > tag before the radio button group is more difficult, because there are
> > plenty of table tags before.
>
> It isn't so hard.  Did you look at the "stop" example I gave?
>
> > >     my $text = "stop this and stop that and " .
> > >                "this is the center " .
> > >                "and stop stop again";
> > >     ( $extr) = $text =~ /.*(stop.*this is the center.*?stop)/;
> > >     print $extr || '-failed-', "\n";
>
> Allowing an arbitrary greedy match before capturing the leading "stop"
> eats as much text as possible while still allowing the match.  So it
> finds the "stop" nearest to the center text with no more intervening
> "stop"s.  That's what you want, isn't it?
> 
> Anno

Yep you are right...



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

Date: Sun, 27 Aug 2006 05:09:25 -0700
From: robic0
Subject: Re: Match regular expression from LEFT to right
Message-Id: <rj23f2lklfm8cca8agcs4ejspqrussalks@4ax.com>

On 27 Aug 2006 01:49:39 -0700, "fritz-bayer@web.de" <fritz-bayer@web.de> wrote:

>
>anno4000@radom.zrz.tu-berlin.de wrote:
>> fritz-bayer@web.de <fritz-bayer@web.de> wrote in comp.lang.perl.misc:
>> > anno4000@radom.zrz.tu-berlin.de wrote:
>> > > fritz-bayer@web.de <fritz-bayer@web.de> wrote in comp.lang.perl.misc:
>> > > > anno4000@radom.zrz.tu-berlin.de wrote:
>> > > > > fritz-bayer@web.de <fritz-bayer@web.de> wrote in comp.lang.perl.misc:
>>
>> [...]
>>
>> > So let me explain this words - as I did below. I'm trying to capture a
>> > group of radio buttons which resides inside a table in the middle of a
>> > html document, which contains lots of tags and text.
>> >
>> > Capturing the back of the html table after the radio buttons is easy as
>> > a ".*?</table>, will do the job. However, capturing the first <table>
>> > tag before the radio button group is more difficult, because there are
>> > plenty of table tags before.
>>
>> It isn't so hard.  Did you look at the "stop" example I gave?
>>
>> > >     my $text = "stop this and stop that and " .
>> > >                "this is the center " .
>> > >                "and stop stop again";
>> > >     ( $extr) = $text =~ /.*(stop.*this is the center.*?stop)/;
>> > >     print $extr || '-failed-', "\n";
>>
>> Allowing an arbitrary greedy match before capturing the leading "stop"
>> eats as much text as possible while still allowing the match.  So it
>> finds the "stop" nearest to the center text with no more intervening
>> "stop"s.  That's what you want, isn't it?
>> 
>> Anno
>
>Yep you are right...

Yeah but its wrong. Don't patronize anbody here dude, your credibility dollar
has about .02 left. Post your problem text and stop playing games.

I've held off telling you the true story with searches/matches/anchors because
its about ten goddamed miles over your head, and I want to be nice. Stop 
thinking your have just discovered the truth of the universe. You haven't,
any neophite Perl programmer discovers this paradigm.

Wake up and smell the coffee.......


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

Date: Sun, 27 Aug 2006 13:02:13 GMT
From: zentara <zentara@highstream.net>
Subject: Re: Perl's GUI
Message-Id: <4m53f2pk3lsitgaf8136dbheqp71jdgs7v@4ax.com>

On Sat, 26 Aug 2006 17:37:03 +0100, Ben Morrow <benmorrow@tiscali.co.uk>
wrote:

>Quoth zentara <zentara@highstream.net>:
>> 
>> WxPerl is based on Perl/Gtk2.
>
>No it isn't. wxPerl is a Perl binding for the wxWidgets toolkit, which
>is a cross-platform GUI. It can be built to use Gtk; it can also use
>Motif or raw X11 under unix, and native gui widgets under Max OS X and
>Win32.

Yeah but in reality, almost every linux distribution builds it on Gtk2.
And when building it, it will default to Gtk2 if it's found.

>> Now for the bad news. Perl/Gtk2 can make it very difficult to do
>> what is simple in Tk. The most obvious thing is colorization of
>> widgets. Gtk2 has a powerful "theme" system, so you can make all your
>> apps look like your other Gtk2 apps like mozilla. BUT, that same theme
>> system, makes it quite difficult to give custom colors and fonts  to
>> individual widgets.
>> Tk dosn't have that problem.  
>
>It's not a problem: that's the *whole* *point*. You shouldn't be messing
>about making everything silly colours: it just makes things harder for
>your users.

Why does making a textbox with a black background, (which is easier on
the eyes), make things hard for the user?

I was chastised by other Perl/Gtk2 users for saying this, and their
reason was that "themes" should never be tampered with..... like
some mantra learned in CS classes.

But I've written alot of little apps, and for appearance, and ease on
the eyes, colorization is very useful. 


A few other comparisons bewtween Tk and Gtk2 (and WxWidgets built on
Gtk2).

1. Tk is very easy to install, and install cross-platform, thanks to
ActiveState's inclusion of it in it's Perl for windows.
Gtk2 on the other hand, can be a nightmare of interrelated packages,
which must be installed in a particular order. Window's versions are
finicky and difficult to get running.

2. The Canvas, which in my opinion, is the best all around widget, is
quite good on Tk. And has a big-brother named Zinc, which has many
extra features like transparency, rotations and scaling.
In Gtk2, the Canvas is "up in the air" and cannot be counted on to
be stable into the future. Apparently their are competing replacements
coming along, but no one knows where it will settle out. So Canvas
use on Gtk2 based apps is an iffy proposition right now.


Finally, don't get me wrong. I like and support Gtk2. But it is much
harder to learn and use than Tk. 
I do find the thoughtful design,
where all widgets all based on Glib's Gobjects, very satisfying, in the
sense that it makes it apparent that there are brains behind the design.

I  think that in about 5-10 years, when Perl/Gtk2 has had time to work
out better docs, and maybe have a book published on how to
use it, it will be the best thing going.

But for now, I reach for Tk first.


-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


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

Date: Sun, 27 Aug 2006 14:34:12 GMT
From: zentara <zentara@highstream.net>
Subject: Re: Perl's GUI
Message-Id: <l5b3f2dr18217ud8ji0dffh0sul813k8n7@4ax.com>

On Sun, 27 Aug 2006 13:02:13 GMT, zentara <zentara@highstream.net>
wrote:

>On Sat, 26 Aug 2006 17:37:03 +0100, Ben Morrow <benmorrow@tiscali.co.uk>
>wrote:
>
>>Quoth zentara <zentara@highstream.net>:
>>> 
>>> WxPerl is based on Perl/Gtk2.
        ^^^^^^^^^^^^^^^^^^^^^^^^^
>>
>>No it isn't. wxPerl is a Perl binding for the wxWidgets toolkit, which
>>is a cross-platform GUI. It can be built to use Gtk; it can also use
>>Motif or raw X11 under unix, and native gui widgets under Max OS X and
>>Win32.
>
>Yeah but in reality, almost every linux distribution builds it on Gtk2.
>And when building it, it will default to Gtk2 if it's found.

Sorry, I did make a mistake there.
I just downloaded the latest WxWidgets and it does use X11 by default.
The WxWidgets c libs did build Ok.

But I still couldn't get wxPerl going.
First Wx-0.56 said I needed Module::Pluggable and  Alien-wxWidgets
Ok, 2 prerequites, no big deal, but when building
Alien-wxWidgets I get errors:

Manifying blib/lib/Alien/wxWidgets.pm -> blib/libdoc/Alien::wxWidgets.3
'gl' library not found at inc/My/Build/Any_wx_config.pm line 141.
'animate' library not found at inc/My/Build/Any_wx_config.pm line 141.
'fl' library not found at inc/My/Build/Any_wx_config.pm line 141.
'stc' library not found at inc/My/Build/Any_wx_config.pm line 141.
'deprecated' library not found at inc/My/Build/Any_wx_config.pm line
141.
'gizmos' library not found at inc/My/Build/Any_wx_config.pm line 141.
'ogl' library not found at inc/My/Build/Any_wx_config.pm line 141.
'plot' library not found at inc/My/Build/Any_wx_config.pm line 141.
'mmedia' library not found at inc/My/Build/Any_wx_config.pm line 141.
'svg' library not found at inc/My/Build/Any_wx_config.pm line 141.

#########################################################
So I'm not going through all those problems, when Tk builds just
fine with

perl Makefile.PL
make
make install

Sorry, I still say WxPerl is too much hassle, let alone there are no
docs.

I still maintain Tk still is easiest for a new gui programmer.
Followed second by Perl/Gtk2 (which does build and install fine)


-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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