RE: RE help

2006-05-05 Thread Hsu, David








Daniel,

I was able to utilize the suggestions from
the others.  I will also take a look at XML::Simple.

 

Thanks,

David

 









From: Daniel McBrearty
[mailto:[EMAIL PROTECTED] 
Sent: Thursday, May 04, 2006 4:33
PM
To: Hsu, David
Cc:
perl-win32-users@listserv.activestate.com
Subject: Re: RE help



 

looks to me like you are reinventing the wheel here ...

this is XML, right?

there are numerous XML parsers on CPAN. Try XML::Simple  

something like this should do it:

ue XML::Simple;

my $x = XMLin($string);

now all your info should be a complex data structure under the ref $x.

Try it, maybe use Data::Dumper to see what the data structure looks like, then
get your data out by navigating the structure.

( of course, you have to install XML::Simple first ... I assume it's on
ActiveState ...)

-- 
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab
trainer
BTW : 0873928131 






___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: RE help

2006-05-05 Thread Thomas, Mark - BLS CTR
David Hsu wrote:
> I only want the name in last  tag and the   
> (i.e. Susan Miers President)

You may want to look into XPath. Here's a sample:

use XML::XPath;

my $xml = qq(
  
  John Smith,
  Susan  Miers
  President
  
);

my $x = XML::XPath->new(xml=>$xml);

my $name = $x->findvalue('normalize-space(//Name[position()=last()])');
my $title = $x->findvalue('//JobTitle');

print "$name $title\n"; #prints "Susan Miers President"

-- 
Mark Thomas 
Internet Systems Architect
___
BAE SYSTEMS Information Technology 
2525 Network Place
Herndon, VA  20171  USA 


___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: RE help

2006-05-04 Thread Daniel McBrearty
looks to me like you are reinventing the wheel here ...



this is XML, right?



there are numerous XML parsers on CPAN. Try XML::Simple  



something like this should do it:



ue XML::Simple;



my $x = XMLin($string);



now all your info should be a complex data structure under the ref $x.



Try it, maybe use Data::Dumper to see what the data structure looks like, then get your data out by navigating the structure.



( of course, you have to install XML::Simple first ... I assume it's on ActiveState ...)
-- Daniel McBreartyemail : danielmcbrearty at gmail.comwww.engoi.com : the multi - language vocab trainerBTW : 0873928131
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: RE help

2006-05-04 Thread James Sluka

1. There is a missing semicolon on the first line.
2. Does "$string" really contain line breaks? If it does you need the 
"s" option in the regex.


how about this;
v
use strict;

my $string = 'John Smith,
Susan Miers
President';   # missing semicolon

# assuming $string may contain multiple lines
if ( $string =~ m/.*(.+?)<\/Name>.*(.+?)<\/JobTitle>/s ) {

   my $personName = $1;
   my $jobTitle   = $2;
   print qq{personName==$personName==\n};
   print qq{jobTitle==$jobTitle==\n\n};

   $personName =~ s/<[^>]+>//gs;  # remove extra tags
   $personName =~ s/\s\s+/ /gs;   # clean up the whitespace
   print qq{personName==$personName==\n};
   print qq{jobTitle==$jobTitle==\n\n};

} else {
   print "No name found in ==$string==\n";  # oops
}
^^^

Which gives;
personName==Susan Miers==
jobTitle==President==

personName==Susan Miers==
jobTitle==President==




Hsu, David wrote:


Hi,
I am trying to parse this string and not able to get the results that I
need.  Can someone please help.  Thanks in advance. -David

I am trying this:

$string = 'John Smith,
Susan  Miers
President'

$string =~ m/.*(.+?<\/Name>).*(.+?<\/JobTitle>)/;

I only want the name in last  tag and the   (i.e. Susan
Miers President)

Also, the  and  tag may or may not be there at times.

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

 


___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: RE: help with pdf file download?

2002-10-16 Thread cerberos

Thanks Josh for noticing that typo.
unfortunately that's not the problem. 

I simply cut'n'pasted the wrong version of code yesterday (I had many different 
attempts with various methods and I tried at the end to have a separate case for PDF 
which at the end I aborted forgotting to change it back to 'eq').

My original correct code is: 
if (-B $file) { #binary file...
 
   $file =~ m|(.*/)(.+)\.([^\.]+)$|;
   my $ext = $3; my $mimetype;

   #most common mime types
   if (uc($ext) eq "PDF") { $mimetype="application/pdf";}  
   elsif (uc($ext) eq "DOC") { $mimetype="application/msword";}
   elsif (uc($ext) eq "PPT") { $mimetype="application/powerpoint";}
   elsif (uc($ext) eq "ZIP") { $mimetype="application/x-zip-compressed";}
   elsif (uc($ext) eq "EXE") { $mimetype="application/octet-stream";}
   elsif (uc($ext) eq "EPS") { $mimetype="application/postscript";}
   elsif (uc($ext) eq "PS")  { $mimetype="application/postscript";}
   elsif (uc($ext) eq "GZ")  { $mimetype="application/x-gzip";}
   elsif (uc($ext) eq "LATEX") { $mimetype="application/x-latex";}
   elsif (uc($ext) eq "TAR") { $mimetype="application/x-tar";}
   elsif (uc($ext) eq "EXE") { $mimetype="application/octet-stream";}   

  my $size = -s "$file";

 
  open(INFILE, "$file") || die &img_not_found;
binmode(INFILE);
binmode(STDOUT);
print "Content-type: $mimetype\n\n";
while () {
print $_;
}
close(INFILE);
   

  } #binary mode file


The mime type is correctly set (I am sure as I debugged it step by step and printed 
out everything at each step). 
The output (downloaded file) is perfectly working for .doc files and for .zip files 
(the ones I tried).

But for PDFs, the output is all the time a 2kb with the PDF header and binary parts. 
But nothing to do with the original PDF. 

Any suggestions? I tried with an IIS server on WinNT and Sambar server on WinNT. 
Can anyone test the code above or give further suggestions?

Thanks

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs