Re: Tree data structure

2007-11-20 Thread vijay
Thanks for the help. I have another question. How do I compute the
depth of those trees. Do I need to first find the root of the tree and
then try of find the depth of the tree? Is there a more efficient
algorithm to find the depth? Is there a "Tree" module that I can use.
I could only find something called Tree::Nary which is not very useful
to me. Thank you.

--
Vijay


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




How to get the name of the variable a reference is "pointing" at

2007-11-20 Thread Frank Bergemann
Hi,

foreach my $ref (\%Hash1, \%Hash2, \%Hash3) {
while(my ($key, $value) = each(%$ref)) {
debug ("$key -> $value")
}
}

I'd like to prefix the name of the hash for the elements in my
debug(...).
How to get the name of what $ref is actually pointing at currenty
(%Hash1, Hash2, Hash3)?

- thanks!

rgds!

Frank


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: How to get the name of the variable a reference is "pointing" at

2007-11-20 Thread Paul Lalli
On Nov 20, 6:22 am, [EMAIL PROTECTED] (Frank Bergemann) wrote:
> foreach my $ref (\%Hash1, \%Hash2, \%Hash3) {
> while(my ($key, $value) = each(%$ref)) {
> debug ("$key -> $value")
> }
> }
>
> I'd like to prefix the name of the hash for the elements in my
> debug(...).
> How to get the name of what $ref is actually pointing at currenty
> (%Hash1, Hash2, Hash3)?

In general, you don't.   Obvious workaround - use a hash:

my %hash_named = (hash1 => \%Hash1, hash2 => \%Hash2, hash3 => \
%Hash3);
while (my ($name, $ref) = each %hash_named) {
   while (my ($key, $val) = each %{$ref}) {
  debug("$name: $key => $val");
   }
}

Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




how to use $Storable::interwork_56_64bit

2007-11-20 Thread [EMAIL PROTECTED]
Hello,

Please tell me how can I use $Storable::interwork_56_64bit

Thanks in advance

Regards
Saurabh


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




RE: :FTP troubles with passive

2007-11-20 Thread RICHARD FERNANDEZ
 

> -Original Message-
> From: Andrew Curry [mailto:[EMAIL PROTECTED] 
> 
> Passive - If set to a non-zero value then all data transfers 
> will be done using passive mode. If set to zero then data 
> transfers will be done using active mode.

Sheesh. I must've read that line 50 times but never that way.

If I say:

 my $ftp = Net::FTP -> new($server, Passive => 0)...

it does indeed use active mode.

Sometimes you just need another pair of eyes :)

Thanks!

richf

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Net::FTP troubles with passive

2007-11-20 Thread RICHARD FERNANDEZ
Hi Folks,

I have a script that sends a file to a vendor. After running tcpdump I
can see that it's trying to do a passive mode transfer which our
firewall is having problems with. I would like to turn this off and
specify an active mode transfer, but the doco for Net::FTP only talks
about turning passive mode _on_. It's silent about turning it off, which
would make me think that "off" should be the default. AFAIK,
active/passive mode selection is a client issue...

Has anyone seen this before?

Thanks for any replies!

richf

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




RE: :FTP troubles with passive

2007-11-20 Thread Andrew Curry
Passive - If set to a non-zero value then all data transfers will be done
using passive mode. If set to zero then data transfers will be done using
active mode.

-Original Message-
From: RICHARD FERNANDEZ [mailto:[EMAIL PROTECTED] 
Sent: 20 November 2007 15:25
To: beginners@perl.org
Subject: Net::FTP troubles with passive

Hi Folks,

I have a script that sends a file to a vendor. After running tcpdump I
can see that it's trying to do a passive mode transfer which our
firewall is having problems with. I would like to turn this off and
specify an active mode transfer, but the doco for Net::FTP only talks
about turning passive mode _on_. It's silent about turning it off, which
would make me think that "off" should be the default. AFAIK,
active/passive mode selection is a client issue...

Has anyone seen this before?

Thanks for any replies!

richf

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/



This e-mail is from the PA Group.  For more information, see
www.thepagroup.com.

This e-mail may contain confidential information.  Only the addressee is
permitted to read, copy, distribute or otherwise use this email or any
attachments.  If you have received it in error, please contact the sender
immediately.  Any opinion expressed in this e-mail is personal to the sender
and may not reflect the opinion of the PA Group.

Any e-mail reply to this address may be subject to interception or
monitoring for operational reasons or for lawful business practices.





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Tree data structure

2007-11-20 Thread Chas. Owens
On Nov 19, 2007 8:37 PM, vijay <[EMAIL PROTECTED]> wrote:
> Thanks for the help. I have another question. How do I compute the
> depth of those trees. Do I need to first find the root of the tree and
> then try of find the depth of the tree? Is there a more efficient
> algorithm to find the depth?
snip

If you are going to use the Graph module then you can simply say
$g->longest_path.  In scalar context it will return the depth (in list
context it returns the actual path).

snip
> Is there a "Tree" module that I can use.
> I could only find something called Tree::Nary which is not very useful
> to me. Thank you.
snip

If you search CPAN* for tree you will find many implementations, but
it is not common to use data structures directly.  Unless you are
doing something no one else has ever done, you are likely to find a
module on CPAN that does what you want.  What data structure it uses
to do it is usually unimportant.  Perhaps if you told us what you need
a tree for (because you almost never need a tree for itself) we could
suggest a good high level module.

* http://search.cpan.org/search?q=tree

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




what's wrong with my http header

2007-11-20 Thread Francois
I tried to get data from a site which use cookies and redirect the
user, I spend a lot of time with the same result: connection timed out
until I realised that all was fine if I did'nt send the header...

Thanks for any explanations !!!
Francois

here is my code:

  use strict;
use warnings;

use LWP;
use HTML::Parser;
use HTML::FormatText;
use HTML::Tree;
# use DateTime::Duration;
use HTTP::Headers;
use HTTP::Cookies;
use HTTP::Cookies::Netscape;
use CGI qw(header -no_debug);


my $h = HTTP::Headers->new(
Accept => "text/xml,application/xml,application/xhtml+xml,text/
html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
Host => "www.unifr.ch",
   );

$h->server("Apache/2.0.46 (Red Hat)");
$h->user_agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:
1.8.1.9) Gecko/20071025 Firefox/2.0.0.9");

my $reflink = "http://linkinghub.elsevier.com/retrieve/pii/
S002013830795";


my $c = HTTP::Cookies::Netscape->new(file=>'cookies.txt',
autosave=>"1");
my $ua_short = LWP::UserAgent->new(cookie_jar => $c, timeout=>
20);
   $ua_short->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:
1.8.1.9) Gecko/20071025 Firefox/2.0.0.9");
# with this line the header is send with my request and it does
not work
   # my $req = HTTP::Request->new(GET=>$reflink, $h);

  #with this line it's ok 
my $req = HTTP::Request->new(GET=>$reflink);

 my $response =$ua_short->request($req);
print header;
print $response->status_line,"\n";
my $formatter = HTML::FormatText->new();

if ($response->is_success) {
my $tree = 
HTML::TreeBuilder->new->parse($response->content);
my $ascii = $formatter->format($tree);
$tree->delete();
print $ascii;
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: what's wrong with my http header

2007-11-20 Thread Tom Phoenix
On 11/20/07, Francois <[EMAIL PROTECTED]> wrote:

> what's wrong with my http header

You may get a faster, better answer if you ask in a forum concerning
http headers and related topics; this forum is for Perl beginners.

> I realised that all was fine if I did'nt send the header...

So, everything works now?

If the remote server isn't doing what you want it to do, try asking in
a forum about servers and how to make them work for you. Good luck
with it!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: how to use $Storable::interwork_56_64bit

2007-11-20 Thread Tom Phoenix
On 11/20/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> Please tell me how can I use $Storable::interwork_56_64bit

Have you seen the documentation for Storable? Do you need something
that's not in there?

http://perldoc.perl.org/Storable.html

Cheers!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: How to get the name of the variable a reference is "pointing" at

2007-11-20 Thread Frank Bergemann
Hi Paul,

just another level of indirection
- should have known that :-)

- many thanks!

rgds!

Frank


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Tree data structure

2007-11-20 Thread Chas. Owens
On Nov 20, 2007 12:30 PM, Vijay Kumar Adhikari <[EMAIL PROTECTED]> wrote:
> > Perhaps if you told us what you need
> > a tree for (because you almost never need a tree for itself) we could
> > suggest a good high level module.
>
> I am trying to analyze BGP routing table available at RouteViews
> routing archive. The data looks something like
>
> 1.0.0.0/8 1 2 3 4 5 6
>  7 4 5 6
>  8 9 6
> 2.0.0.0/8 1 2 10 11
>  7 4 11
> 3.0.0.0/8 1 12 13
>  7 14
>  8 12 13
>
> For 1.0.0.0/8, the path make a tree rooted at 6 and 1, 7 and 8
> appearing as the leaves, for 2.0.0.0/8 the root is at 11 and 1 and 7
> are leaves. For 3.0.0.0/8 the structure is not a tree. We may thing of
> the structure as two trees rooted at 13 and 14 respectively. There may
> be many other cases possible.
>
> What I want to do is to see how many of the structures are trees? How
> many are not? If not how many connected components are there? If the
> structure is a tree what is the depth of the tree, what is the maximum
> fanout etc. I want to see if the similarity of two structure tell me
> some relationship between the prefixes. For instance, do two prefixes
> owned by the same organization have the same structure. And things
> like that. I am not specifically looking for something. I am trying to
> study the structures to see if there is something interesting there.
>
> Maybe this time I am using trees just for trees :)
>
> --
> Vijay
>

It looks to me like the Graph module is what you want then.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Tree data structure

2007-11-20 Thread Vijay Kumar Adhikari
> Perhaps if you told us what you need
> a tree for (because you almost never need a tree for itself) we could
> suggest a good high level module.

I am trying to analyze BGP routing table available at RouteViews
routing archive. The data looks something like

1.0.0.0/8 1 2 3 4 5 6
 7 4 5 6
 8 9 6
2.0.0.0/8 1 2 10 11
 7 4 11
3.0.0.0/8 1 12 13
 7 14
 8 12 13

For 1.0.0.0/8, the path make a tree rooted at 6 and 1, 7 and 8
appearing as the leaves, for 2.0.0.0/8 the root is at 11 and 1 and 7
are leaves. For 3.0.0.0/8 the structure is not a tree. We may thing of
the structure as two trees rooted at 13 and 14 respectively. There may
be many other cases possible.

What I want to do is to see how many of the structures are trees? How
many are not? If not how many connected components are there? If the
structure is a tree what is the depth of the tree, what is the maximum
fanout etc. I want to see if the similarity of two structure tell me
some relationship between the prefixes. For instance, do two prefixes
owned by the same organization have the same structure. And things
like that. I am not specifically looking for something. I am trying to
study the structures to see if there is something interesting there.

Maybe this time I am using trees just for trees :)

-- 
Vijay

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Need help with date-time and output

2007-11-20 Thread Gerald Wheeler
Running Perl 5.6.1 on Solaris 9 SPARC
No (access to) modules available other than what comes with the basic perl 
installation.

I have a file: ifiln.csv as such:
Julian Day of the year, value
1,4144.34
2,4144.38
3,4144.38
4,4144.38
5,4144.44
6,4144.48
7,4144.48
8,4144.50
9,4144.50
10,4144.48
11,4144.50
12,4144.52
13,4144.52
14,4144.54
15,4144.54
16,4144.56
17,4144.58
18,4144.58
19,4144.60
20,4144.62
.
365,4147.42
366,4147.56 (Leap Year)
OR
This may be (as shown below) between the current date and the last day of the 
year or with missing data 
331,
332,
333,
...
365,
366, (Leap Year)
--
I would like to create a new file: ofiln based on the data in ifiln...  Days 
without values (missing data or future date) would be set as null.
If this is run on November 2, 2007 then all days between November 3, 2007 and 
December 31, 2007 would have a date and a "null value" for
parameter value.

Passed in as commandline arguments
arg1 (ex: 201)
arg2 (ex: 11)
startdate (2007) - January 1, 2007
The data would be incremented as per column one value of ifiln. 

The output file should look something like this:
insert some text1, 366, insert some text2 201, insert some text3 11, 
4144.62, some text4, 2007/11/20, some text5

below is what I have... can someone assist...  Thanks

*** I do NOT know how to increment (and format as "2007/01/01") date so that it 
crosses over for each new month and know when it is a leap year.
Also, Is they a better way to write this??  

*
#!/usr/bin/perl

use strict;
use warnings;

my $ifiln = 'abc.csv';
my $ofiln = 'xyz.txt';

# get start year () from command line
my($rsvr, $rdt, $dyr) = @ARGV;

print "Year input argument: $ARGV[0] - $ARGV[1] - $ARGV[2]\n";
print "Year input: $dyr, $rsvr, $rdt\n";

my(@data_line, @rsvrs); # start out empty

my $line = "default text";  # start with some default text
my $cntr = 0;   # line cntr

open RDATA, $ifiln or die "can not open file: $ifiln: $!\n";

while($line = )
{
@data_line = split(/,/,$line);
$rsvrs[$cntr]{jday} = $data_line[0];
$rsvrs[$cntr]{rval} = $data_line[1];
$cntr++;
}

close(RDATA);

$cntr = 0;
open(ORDATA, ">$ofiln");

foreach(@rsvrs)
{
print ORDATA "insert some text1,";
print ORDATA $rsvrs[$cntr]{jday};
print ORDATA "insert some text2 $rsvr,";
print ORDATA "insert some text3 $rdt,";
print ORDATA chomp($rsvrs[$cntr]{rval});
print ORDATA "some text4";
print ORDATA "Calendar Date 2007/11/20 format - How? ($dyr)";
print ORDATA "some text5\n";
$cntr++;
}

close(ORDATA);




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Need help with date-time and output

2007-11-20 Thread Tom Phoenix
On 11/20/07, Gerald Wheeler <[EMAIL PROTECTED]> wrote:

> Running Perl 5.6.1 on Solaris 9 SPARC
> No (access to) modules available other than what comes with the basic
> perl installation.

> *** I do NOT know how to increment (and format as "2007/01/01") date so
> that it crosses over for each new month and know when it is a leap year.

That's a non-trivial problem. Have you seen the date and time modules
available on CPAN? You can download and install a module that will
help you with your task.

http://search.cpan.org

Cheers!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Rename Files

2007-11-20 Thread Dr.Ruud
"Allison Baldoni" schreef:

> I'm trying to write a script that will browse a windows directory and
> rename all files in it and its subdirectories. A file name such as
> 123TEST987.docneeds to be renamed to
> 123987.doc.  all files have TEST in the name.
> I am unsure of the best way to do this.  I have been trying to use
> globbing and substitution (to substitute TEST with nothing). I am
> unsure how to rename files in multiple directories.

A perfect job for IO::All.

-- 
Affijn, Ruud

"Gewoon is een tijger."

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Need help with date-time and output

2007-11-20 Thread John W . Krahn
On Tuesday 20 November 2007 14:00, Gerald Wheeler wrote:
> Running Perl 5.6.1 on Solaris 9 SPARC
> No (access to) modules available other than what comes with the basic
> perl installation.
>
> I have a file: ifiln.csv as such:
> Julian Day of the year, value
> 1,4144.34
> 2,4144.38
> 3,4144.38

[ SNIP ]

So far, so good.


> 366,4147.56 (Leap Year)

Is the text ' (Leap Year)' actually part of the file data?  Is there 
some place in the world where 366 days is *not* a leap year?


> OR
> This may be (as shown below) between the current date and the last
> day of the year or with missing data 331,
> 332,
> 333,
> ...
> 365,
> 366, (Leap Year)
> --
> I would like to create a new file: ofiln based on the data in
> ifiln...  Days without values (missing data or future date) would be
> set as null. If this is run on November 2, 2007 then all days between
> November 3, 2007 and December 31, 2007 would have a date and a "null
> value" for parameter value.

That seems easy enough.


> Passed in as commandline arguments
> arg1 (ex: 201)
> arg2 (ex: 11)
> startdate (2007) - January 1, 2007
> The data would be incremented as per column one value of ifiln.

What exactly do arg1 and arg2 represent?  Which data would be 
incremented?


> The output file should look something like this:
> insert some text1, 366, insert some text2 201, insert some
> text3 11, 4144.62, some text4, 2007/11/20, some text5

Where did the date 2007/11/20 come from?


> below is what I have... can someone assist...  Thanks
>
> *** I do NOT know how to increment (and format as "2007/01/01") date
> so that it crosses over for each new month and know when it is a leap
> year. Also, Is they a better way to write this??
>
> *
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my $ifiln = 'abc.csv';
> my $ofiln = 'xyz.txt';
>
> # get start year () from command line
> my($rsvr, $rdt, $dyr) = @ARGV;

What exactly do $rsvr and $rdt represent?


> print "Year input argument: $ARGV[0] - $ARGV[1] - $ARGV[2]\n";
> print "Year input: $dyr, $rsvr, $rdt\n";
>
> my(@data_line, @rsvrs);   # start out empty

@data_line should be declared inside the loop.


> my $line = "default text";# start with some default text

$line should be declared inside the loop.


> my $cntr = 0; # line cntr

$cntr is not needed.


> open RDATA, $ifiln or die "can not open file: $ifiln: $!\n";
>
> while($line = )

You should declare $line here:

while ( my $line =  )


> {
> @data_line = split(/,/,$line);

You should declare @data_line here:

my @data_line = split( /,/, $line );


> $rsvrs[$cntr]{jday} = $data_line[0];
> $rsvrs[$cntr]{rval} = $data_line[1];
> $cntr++;

You don't need $cntr, just use push():

push @rsvrs, { jday => $data_line[ 0 ], rval => $data_line[ 1 ] };


> }
>
> close(RDATA);
>
> $cntr = 0;

Again, $cntr is not needed.


> open(ORDATA, ">$ofiln");

You should *always* verify that the file opened correctly:

open ORDATA, '>', $ofiln or die "Cannot open '$ofiln' $!";


> foreach(@rsvrs)
> {
>   print ORDATA "insert some text1,";
>   print ORDATA $rsvrs[$cntr]{jday};

You are looping over each element of @rsvrs so in every iteration the 
value of $_ is a reference to a hash and you can just dereference it:

print ORDATA $_->{ jday };


>   print ORDATA "insert some text2 $rsvr,";
>   print ORDATA "insert some text3 $rdt,";
>   print ORDATA chomp($rsvrs[$cntr]{rval});

chomp() returns the number of $/ values that were removed from its 
argument(s) so that is not what you want to do here.  You should 
probably have chomped the data when you input it.

As above, you can dereference the hash directly:

print ORDATA $_->{ rval };


>   print ORDATA "some text4";
>   print ORDATA "Calendar Date 2007/11/20 format - How? ($dyr)";

Calendar Date from where?


>   print ORDATA "some text5\n";
> $cntr++;
> }
>
> close(ORDATA);



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Need help with date-time and output

2007-11-20 Thread Gunnar Hjalmarsson

Tom Phoenix wrote:

On 11/20/07, Gerald Wheeler <[EMAIL PROTECTED]> wrote:

No (access to) modules available other than what comes with the basic
perl installation.

*** I do NOT know how to increment (and format as "2007/01/01") date so
that it crosses over for each new month and know when it is a leap year.


That's a non-trivial problem.


Not too complicated either. This piece of code may or may not help the 
OP move forward:


use Time::Local;

sub nextday {
my ($y, $m, $d) = split /\//, shift;
my $t = timegm 0, 0, 0, $d, $m-1, $y;
($d, $m, $y) = ( gmtime($t+24*60*60) )[3..5];
sprintf '%d/%02d/%02d', $y+1900, $m+1, $d;
}

print nextday('2007/11/20');

Also, Gerald, did you ever answer the questions that Tom asked you in 
http://www.mail-archive.com/beginners@perl.org/msg90026.html ?


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

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Need help with date-time and output

2007-11-20 Thread Tom Phoenix
On 11/20/07, Eric Krause <[EMAIL PROTECTED]> wrote:

>  I think he can't download modules.

I think he *thinks* he can't download modules.

Cheers!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: outlook module

2007-11-20 Thread oryann9


Why not just create a message filter or rule or whatever Outlook calls
it (or multiple ones for various criteria)?


>
>   
I did and it I cannot get it to work.





  

Be a better pen pal. 
Text or chat with friends inside Yahoo! Mail. See how.  
http://overview.mail.yahoo.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: what's wrong with my http header

2007-11-20 Thread Rob Dixon

Francois wrote:

I tried to get data from a site which use cookies and redirect the
user, I spend a lot of time with the same result: connection timed out
until I realised that all was fine if I did'nt send the header...

Thanks for any explanations !!!
Francois

here is my code:

  use strict;
use warnings;

use LWP;
use HTML::Parser;
use HTML::FormatText;
use HTML::Tree;
# use DateTime::Duration;
use HTTP::Headers;
use HTTP::Cookies;
use HTTP::Cookies::Netscape;
use CGI qw(header -no_debug);


my $h = HTTP::Headers->new(
Accept => "text/xml,application/xml,application/xhtml+xml,text/
html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
Host => "www.unifr.ch",
   );

$h->server("Apache/2.0.46 (Red Hat)");
$h->user_agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:
1.8.1.9) Gecko/20071025 Firefox/2.0.0.9");

my $reflink = "http://linkinghub.elsevier.com/retrieve/pii/
S002013830795";


my $c = HTTP::Cookies::Netscape->new(file=>'cookies.txt',
autosave=>"1");
my $ua_short = LWP::UserAgent->new(cookie_jar => $c, timeout=>
20);
   $ua_short->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:
1.8.1.9) Gecko/20071025 Firefox/2.0.0.9");
# with this line the header is send with my request and it does
not work
   # my $req = HTTP::Request->new(GET=>$reflink, $h);

  #with this line it's ok 
my $req = HTTP::Request->new(GET=>$reflink);

 my $response =$ua_short->request($req);
print header;
print $response->status_line,"\n";
my $formatter = HTML::FormatText->new();

if ($response->is_success) {
my $tree = 
HTML::TreeBuilder->new->parse($response->content);
my $ascii = $formatter->format($tree);
$tree->delete();
print $ascii;
}


Hi Francois.

As a general rule it's polite to reduce code as much as possible before
posting it here to ask for help: there's a lot of junk in here that
isn't relevant to the problem and just needs to be waded through before
we can give you an answer.

What's going wrong is that you have a Host header value of www.unifr.ch
but you are sending the request to linkinghub.elsevier.com, which
doesn't have a host of that name and so doesn't reply.

But that's a huge amount of code just to fetch a web page! You may need
some of that stuff but I can't see how you would want all of it. How
about just

  my $ua = LWP::UserAgent->new;
  my $resp = 
$ua->get('http://linkinghub.elsevier.com/retrieve/pii/S002013830795');


which seems to me to do the same thing.

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Conditions and actions in an external chart ?

2007-11-20 Thread Jo for Groups and Lists
Is there a way to store and retrieve code for conditions and actions in
a chart? Something like

Condition   action
$Pet eq "dog"   $suggest.="Buy a Bone?"
$numBiscuits >1 $subTotal+=($numBiscuits*2.00)


($cond,$act)=split(/\t/);
if ($cond) { $act; }

I haven't a clue what I need to look up in the perl docs (to learn) to
accomplish this. Can someone point me in the right direction?
   
Thanks,
Jo 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Invalid Unicode

2007-11-20 Thread Mark Wagner
I've got a program where I could greatly simplify things by
temporarily replacing strings with single characters.  However, the
potential input includes any valid Unicode character.  Assuming that
the invalid characters are never output to anything, are there any
problems that I'd encounter from using code points beyond what Unicode
defines (0x11 and above)?

Thanks,
Mark Wagner

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Invalid Unicode

2007-11-20 Thread Tom Phoenix
On 11/20/07, Mark Wagner <[EMAIL PROTECTED]> wrote:
> I've got a program where I could greatly simplify things by
> temporarily replacing strings with single characters.  However, the
> potential input includes any valid Unicode character.  Assuming that
> the invalid characters are never output to anything, are there any
> problems that I'd encounter from using code points beyond what Unicode
> defines (0x11 and above)?

It's not clear what you're trying to do. You can replace any character
with any other, but whether or not that causes problems depends upon
your ultimate goals.

It sounds as if this isn't a beginning Perl question. You may be able
to get better and faster answers if you inquire in a forum
specifically about Unicode issues.

Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Conditions and actions in an external chart ?

2007-11-20 Thread Tom Phoenix
On 11/20/07, Jo for Groups and Lists <[EMAIL PROTECTED]> wrote:

> Is there a way to store and retrieve code for conditions and actions in
> a chart? Something like
>
> Condition   action
> $Pet eq "dog"   $suggest.="Buy a Bone?"
> $numBiscuits >1 $subTotal+=($numBiscuits*2.00)

You've got a start. It looks as if the piece you're missing is the
coderef: a reference to a chunk of code. You should be able to do what
you want by using references to anonymous subroutines, maybe something
like this:

  my $coderef = sub { my($pet) = shift; return $pet eq "dog" };

You can read about anonymous subroutines in the perlref manpage.

http://perldoc.perl.org/perlref.html

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Invalid Unicode

2007-11-20 Thread Mark Wagner
On Nov 20, 2007 7:28 PM, Tom Phoenix <[EMAIL PROTECTED]> wrote:
>
> On 11/20/07, Mark Wagner <[EMAIL PROTECTED]> wrote:
> > I've got a program where I could greatly simplify things by
> > temporarily replacing strings with single characters.  However, the
> > potential input includes any valid Unicode character.  Assuming that
> > the invalid characters are never output to anything, are there any
> > problems that I'd encounter from using code points beyond what Unicode
> > defines (0x11 and above)?
>
> It's not clear what you're trying to do. You can replace any character
> with any other, but whether or not that causes problems depends upon
> your ultimate goals.

To simplify the question, can I use characters that aren't valid
Unicode, and if so, are there any consequences?

-- 
Mark

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Invalid Unicode

2007-11-20 Thread Tom Phoenix
On 11/20/07, Mark Wagner <[EMAIL PROTECTED]> wrote:

> To simplify the question, can I use characters that aren't valid
> Unicode, and if so, are there any consequences?

Do you mean, suppose I replace every non-ASCII character with some
invalid character:

my $invalid = chr(0x11);
$data =~ s/[^\0-\0177]/$invalid/g;

...Will there be any consequences? Yes; your data will be altered. (Is
that what you're asking?)

Are you trying to ask, will Perl prohibit the use of invalid Unicode
characters? Perl strings should be safe for any data. What happened
when you tried it?

Are you trying to ask, will today's invalid Unicode characters be used
for some valid purpose in tomorrow's Unicode, and thereby break my
program? Maybe.

Are you trying to ask something else?

Cheers!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Invalid Unicode

2007-11-20 Thread Mark Wagner
On Nov 20, 2007 8:22 PM, Tom Phoenix <[EMAIL PROTECTED]> wrote:
> Are you trying to ask, will Perl prohibit the use of invalid Unicode
> characters? Perl strings should be safe for any data.

That's basically what I needed to know, thanks.

-- 
Mark Wagner

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/