[32575] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3846 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 28 00:09:22 2012

Date: Thu, 27 Dec 2012 21:09:07 -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, 27 Dec 2012     Volume: 11 Number: 3846

Today's topics:
        exit if item >10 <bnrj.rudra@gmail.com>
    Re: exit if item >10 <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
    Re: exit if item >10 <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
    Re: exit if item >10 <jurgenex@hotmail.com>
    Re: exit if item >10 <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
    Re: exit if item >10 <jurgenex@hotmail.com>
    Re: exit if item >10 <bnrj.rudra@gmail.com>
    Re: exit if item >10 <glex_no-spam@qwest-spam-no.invalid>
    Re: exit if item >10 <rweikusat@mssgmbh.com>
        import array like structure using perl <bnrj.rudra@gmail.com>
    Re: import array like structure using perl <glex_no-spam@qwest-spam-no.invalid>
    Re: import array like structure using perl <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
    Re: Need porting of Wotan Supercomputer AI into Perl <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 26 Dec 2012 11:06:06 -0800 (PST)
From: Rudra Banerjee <bnrj.rudra@gmail.com>
Subject: exit if item >10
Message-Id: <86cd86b3-b69b-42d7-9dfe-74d8ff8859be@googlegroups.com>

Hello friends, 
I am a perl illiterate, but managed to write a code for gcstar(a package to create catalogue), to export to latex.
I have one little problem. problem is, for movies, the list of actors are written as 
 <actors>
   <line>
    <col>Russell Crowe</col>
    <col></col>
   </line>
   <line>
    <col>Jennifer Connelly</col>
    <col></col>
   </line>
   <line>
    <col>Ed Harris</col>
    <col></col>
   </line>
   <line>
    <col>Paul Bettany</col>
    <col></col>
 ......

and so on. 
I have the code to extract these  *all* Actors listed, i.e., between <actors> to </actors>.
The corresponding piece of code is:
$result .=' & \multirow{1}{4in}{' .  $self->getLocal('actors') . ': \small{' . 
            $self->transformValue ($item->{actors}, 'actors') . '}} \\'
                if $item->{actors};

what I am trying to do is to do a check like:
if ($item->{actors} || $item->{actors}>10);
so that not more then 10 actors name are included.
but this line has no effect. can you kindly help me with this?



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

Date: Wed, 26 Dec 2012 21:31:55 +0200
From: "George Mpouras" <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Subject: Re: exit if item >10
Message-Id: <kbfjbh$1oq2$1@news.ntua.gr>


use XML::Simple;
my $xml = XMLin($event, ContentKey => 'col' );
my @actors = map {$_->{col}[0]} @{$xml->{line}};

print $#actors >= 10 ? 'too many' : @actors





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

Date: Wed, 26 Dec 2012 21:33:13 +0200
From: "George Mpouras" <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Subject: Re: exit if item >10
Message-Id: <kbfjdv$1pa3$1@news.ntua.gr>

use XML::Simple;
my $xml = XMLin(q[

<actors>
   <line>
    <col>Russell Crowe</col>
    <col></col>
   </line>
   <line>
    <col>Jennifer Connelly</col>
    <col></col>
   </line>
   <line>
    <col>Ed Harris</col>
    <col></col>
   </line>
   <line>
    <col>Paul Bettany</col>
    <col></col>
   </line>
</actors>

]);
my @actors = map {$_->{col}[0]} @{$xml->{line}};

print $#actors >= 10 ? 'too many' : @actors





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

Date: Wed, 26 Dec 2012 12:04:38 -0800
From: Jrgen Exner <jurgenex@hotmail.com>
Subject: Re: exit if item >10
Message-Id: <9vlmd8lre7be3n7bgsiv2sisni7u155k61@4ax.com>

"George Mpouras"
<nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam> wrote:
>print $#actors >= 10 ? 'too many' : @actors

Didn't you mean 
	print (scalar @actors) > 10 ? 'too many' : @actors
maybe?

jue


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

Date: Wed, 26 Dec 2012 23:06:35 +0200
From: "George Mpouras" <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Subject: Re: exit if item >10
Message-Id: <kbfot0$2nau$1@news.ntua.gr>



I think that $#array is faster than scalar(@array) - 1 because scalar is 
counting while $# points to the last offset



Ο "Jurgen Exner"  έγραψε στο μήνυμα 
news:9vlmd8lre7be3n7bgsiv2sisni7u155k61@4ax.com...

"George Mpouras"
<nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam> wrote:
>print $#actors >= 10 ? 'too many' : @actors

Didn't you mean
print (scalar @actors) > 10 ? 'too many' : @actors
maybe?

jue 



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

Date: Wed, 26 Dec 2012 13:15:58 -0800
From: Jrgen Exner <jurgenex@hotmail.com>
Subject: Re: exit if item >10
Message-Id: <cvpmd81ut2d6e1n7eou3653b893inrq0ir@4ax.com>

[It wasn't me who messed up the quoting levels and did a TOFU]

"George Mpouras"
<nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam> wrote:
>I think that $#array is faster than scalar(@array) - 1 because scalar is 
>counting while $# points to the last offset
>
>? "Jurgen Exner"  ?????? ??? ?????? 
>news:9vlmd8lre7be3n7bgsiv2sisni7u155k61@4ax.com...
>
>"George Mpouras"
><nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam> wrote:
>>print $#actors >= 10 ? 'too many' : @actors
>
>Didn't you mean
>print (scalar @actors) > 10 ? 'too many' : @actors
>maybe?

Actually no. The length of an array is stored in the array directly and
can be accessed in O(1). No need for counting at all.
Plus $#array will give you the wrong result if someone was stupid enough
to mess with $[.

jue


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

Date: Wed, 26 Dec 2012 13:44:51 -0800 (PST)
From: Rudra Banerjee <bnrj.rudra@gmail.com>
Subject: Re: exit if item >10
Message-Id: <93ad598d-6542-4e27-98b7-8aae76ce09d9@googlegroups.com>

oops....may be I was not clear enough, but the <actors>...</actors> are from gcstar, and I cant really do a "my $xml = XMLin(q[" here!


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

Date: Wed, 26 Dec 2012 16:30:21 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: exit if item >10
Message-Id: <50db7a7d$0$75667$815e3792@news.qwest.net>

On 12/26/12 15:44, Rudra Banerjee wrote:
> oops....may be I was not clear enough, but the<actors>...</actors>  are from gcstar, and I cant really do a "my $xml = XMLin(q[" here!

Simply read the data from STDIN.  Or if you have the output in a file, 
then use the filename as the argument to XMLin().

Read the documentation for the XMLin method. It clearly documents
exactly how to do that and it's very 'simple'.

perldoc XML::Simple



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

Date: Thu, 27 Dec 2012 11:09:48 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: exit if item >10
Message-Id: <871ueblpj7.fsf@sapphire.mobileactivedefense.com>

"George Mpouras"
<nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
writes:
> I think that $#array is faster than scalar(@array) - 1 because scalar
> is counting while $# points to the last offset

Neither scalar(@array) nor $#array counts anything -- they are both
based on using the same internal 'highest-numbered used slot'
variable. As was discussed not that long ago, scalar(@array) is
actually faster because (in 'commonly-used perls') it doesn't need to
deal with the possible case of being assigned to and doesn't need to
take a possible 'base indexing displacement' into account (where it
still exists). When evaluated, $#array ends up pushing a 'magic
scalar' onto the stack which either evaluates to the corresponding
number or provides the 'change array size by assigning to $#array'
facility via assoicated 'magic' (aka a method table). In more recent
perls, this indirection isn't done anymore when the context of the
evaluation is such that an assignment can't happen, eg

	$n = $#array

It is still necessary when $#array is used in an lvalue context. This
includes being passed as argument to a subroutine.



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

Date: Wed, 26 Dec 2012 05:57:00 -0800 (PST)
From: Rudra Banerjee <bnrj.rudra@gmail.com>
Subject: import array like structure using perl
Message-Id: <83ac14ee-d3fc-49a0-9ecd-8288156518d3@googlegroups.com>

Dear friends,
I am trying to write a gcstar export for Latex, and I am a perl-illiterate.
From other gcstar scripts, I am following the pattern.
The gcstar structure is like:

 <item
  id=3D"1"
  title=3D"A Beautiful Mind"
  date=3D"2001"
  time=3D"130 min."
  director=3D"Ron Howard"
  image=3D"Movies_pictures/A_Beautiful_Mind_0.jpg"
  backpic=3D""
  original=3D"A Beautiful Mind"
  webPage=3D"http://www.filmaffinity.com/en/film326587.html##Film affinity =
(EN)"
 >
  <country>
   <line>
    <col>United States</col>
   </line>
  </country>
  <genre>
   <line>
    <col>Drama</col>
   </line>
  </genre>
 </item>

Now, the other fields with key value structure is done, but I don't underst=
and how to get things like   =20
  <country>
   <line>
    <col>United States</col>
   </line>
  </country>

My complete code for the export may be quite too large, but for a snippet, =
what I am trying to do is as:
    sub getItem {
        my ($self, $item, $number) =3D @_;
        my $result;
        return '' if ($self->{options}->{one} &&
                  $item->{number} ne $self->{options}->{disc});
        $result .=3D '\item {\bf ' . $self->transformValue ($item->{title},=
 "title") . "}";
#        $result .=3D " ($item->{date})" if $item->{date};
        # one line for russian cartoons
        if ($self->transformValue ($item->{genre}, 'genre') =3D~
            m/=D0=9C=D1=83=D0=BB=D1=8C=D1=82=D1=84=D0=B8=D0=BB=D1=8C=D0=BC/=
) {
            $result .=3D ' =D0=BC/=D1=84';
        } elsif ($item->{genre} || $item->{director} ||=20
            $item->{audio} || $item->{time}) {
            $result .=3D "\\\\\n\\begin{tabular}{l|ll}\n";
$result .=3D '\multirow{5}{*}{\includegraphics[height=3D1in]{'. $self->tran=
sformValue ($item->{image}, 'image') . '}}'
                if $item->{image};
            $result .=3D'\\ & ' .  $self->getLocal('date') . ': & ' .=20
            $self->transformValue ($item->{date}, 'date') . '\\'
                if $item->{date};

            $result .=3D'\\ & ' .  $self->getLocal('genre') . ': & ' .=20
            $self->transformValue ($item->{genre}, 'genre') . '\\'
                if $item->{genre};
            $result .=3D'\\ & ' . $self->getLocal('director') . ": & $item-=
>{director}\\"
            if $item->{director};

            $result .=3D'\\ & ' .  $self->getLocal('time') . ": & $item->{t=
ime} =D0=BC=D0=B8=D0=BD.\\\\" if $item->{time};
            $result .=3D'\\ & ' .  $self->getLocal('country') . ": & " if $=
item->{country};
            $result .=3D "\n\\end{tabular}\n";
        }
I will be grateful if someone here kindly show me the way.


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

Date: Wed, 26 Dec 2012 10:24:14 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: import array like structure using perl
Message-Id: <50db24ae$0$73610$815e3792@news.qwest.net>

On 12/26/12 07:57, Rudra Banerjee wrote:
> Dear friends,
> I am trying to write a gcstar export for Latex, and I am a perl-illiterate.
>  From other gcstar scripts, I am following the pattern.
> The gcstar structure is like:
>
>   <item
>    id="1"
>    title="A Beautiful Mind"
>    date="2001"
>    time="130 min."
>    director="Ron Howard"
>    image="Movies_pictures/A_Beautiful_Mind_0.jpg"
>    backpic=""
>    original="A Beautiful Mind"
>    webPage="http://www.filmaffinity.com/en/film326587.html##Film affinity (EN)"
>   >
>    <country>
>     <line>
>      <col>United States</col>
>     </line>
>    </country>
>    <genre>
>     <line>
>      <col>Drama</col>
>     </line>
>    </genre>
>   </item>

Looks like XML, so I'd suggest using one of the many XML parsers to
parse and/or access your data.  XML::Simple, XML:XPath, XML::LibXML, etc.

>
> Now, the other fields with key value structure is done, but I don't understand how to get things like
>    <country>
>     <line>
>      <col>United States</col>
>     </line>
>    </country>
>
> My complete code for the export may be quite too large, but for a snippet, what I am trying to do is as:
>      sub getItem {
>          my ($self, $item, $number) = @_;

Include the structure of $item.

use Data::Dumper;
print Dumper( $item );

[...]

> I will be grateful if someone here kindly show me the way.

After you look at the data structure for $item, it should
make it pretty clear how to get the value you're after.

A guess would be:

	print "Country=", $item->{ 'country' }{ 'line' }{ 'col' }, "\n";



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

Date: Wed, 26 Dec 2012 21:00:19 +0200
From: "George Mpouras" <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Subject: Re: import array like structure using perl
Message-Id: <kbfhgc$1dv5$1@news.ntua.gr>

my $event = q[

<item
id="1"
title="A Beautiful Mind"
date="2001"
time="130 min."
director="Ron Howard"
image="Movies_pictures/A_Beautiful_Mind_0.jpg"
backpic=""
original="A Beautiful Mind"
webPage="http://www.filmaffinity.com/en/film326587.html##Film affinity (EN)"
>
<country>
  <line>
   <col>United States</col>
  </line>
</country>
<genre>
  <line>
   <col>Drama</col>
  </line>
</genre>
</item>

];



use XML::Simple;
my $xml = XMLin($event);
print $xml->{id}    ,"\n";
print $xml->{title}    ,"\n";
print $xml->{date}    ,"\n";
print $xml->{time}    ,"\n";
print $xml->{director}    ,"\n";
print $xml->{image}    ,"\n";
print $xml->{backpic}    ,"\n";
print $xml->{original}    ,"\n";
print $xml->{webPage}    ,"\n";
print $xml->{country}{line}{col}    ,"\n";
print $xml->{genre  }{line}{col}    ,"\n";



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

Date: Wed, 26 Dec 2012 21:35:16 +0200
From: "George Mpouras" <nospam.gravitalsun.antispam@spamno.hotmail.anispam.com.nospam>
Subject: Re: Need porting of Wotan Supercomputer AI into Perl
Message-Id: <kbfjhq$1q0q$1@news.ntua.gr>

Hello mentifex,

Please expain with some more words what all this project is about




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

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:

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

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 3846
***************************************


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