HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Need Help In Writing Perl Code
Operating System - HP-UX
1831190
Members
2638
Online
110021
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2008 06:53 PM
01-03-2008 06:53 PM
Hi All,
Kindly Help Me in Getting Perl Code for following problem :
There is an XML file from which I need to get all the elements and their corresponding values. Following string has one such example or xml file. Can anyone help me getting this done?
$string="NG171TDCUAD \\NG171TDCUAD\D: Data 23/11/2005 22:58:03 13,567,900,093 33minutesand52seconds 382 MB/min ";
Or at least if I can get value for element StartTime in any variable say $time? So $time should have value as 23/11/2005 22:58:03.
Kindly Help Me in Getting Perl Code for following problem :
There is an XML file from which I need to get all the elements and their corresponding values. Following string has one such example or xml file. Can anyone help me getting this done?
$string="
Or at least if I can get value for element StartTime in any variable say $time? So $time should have value as 23/11/2005 22:58:03.
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2008 08:45 PM
01-03-2008 08:45 PM
Solution
Hmmm, welcome to the ITRC HPUX Forum.
But pray tell, what does this question have to do with HPUX?
And, have you ever heard about Google?
You should try it some day. It's fun!
Suggested query: perl xml [I feel lucky]
This will likely bring you over to:
http://perl-xml.sourceforge.net/faq/
Read it.
Now if you wanted to just hack it and wack, and support it for the rest of your live, the you could roll your own. Something like:
use strict;
use warnings;
my ($key, %data);
my $i = 0;
my $string='NG171TDCUAD \\NG171T'.
'DCUAD\D: Data 23/11/2005 22:58:03 'zeMedia>13,567,900,09333minutesand52second'.
's 382 MB/min ';
$_ = $string;
while (/<(\w+)>(.*?)<\/\1>/) {
$data{$1} = $2;
$_ = $`.$'
}
foreach $key (sort keys %data) {
$i++;
print "$i: $key --> $data{$key}\n";
}
I've removed the out tag as too confusing for simple code.
And I split the data line explicitlty.
And I used single quotes to avoid interpretation of the he backslashes in the text.
Good luck! (You'll need some.)
Regards,
Hein.
But pray tell, what does this question have to do with HPUX?
And, have you ever heard about Google?
You should try it some day. It's fun!
Suggested query: perl xml [I feel lucky]
This will likely bring you over to:
http://perl-xml.sourceforge.net/faq/
Read it.
Now if you wanted to just hack it and wack, and support it for the rest of your live, the you could roll your own. Something like:
use strict;
use warnings;
my ($key, %data);
my $i = 0;
my $string='
'DCUAD\D: Data
's
$_ = $string;
while (/<(\w+)>(.*?)<\/\1>/) {
$data{$1} = $2;
$_ = $`.$'
}
foreach $key (sort keys %data) {
$i++;
print "$i: $key --> $data{$key}\n";
}
I've removed the
And I split the data line explicitlty.
And I used single quotes to avoid interpretation of the he backslashes in the text.
Good luck! (You'll need some.)
Regards,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2008 12:28 AM
01-04-2008 12:28 AM
Re: Need Help In Writing Perl Code
While it is tempting to parse HTML and XML with regular expressions, please try to avoid it, as you will hit every possible problem you thought could never happen somewhere along the line when the project evolves.
--8<--- test.pl
#!/pro/bin/perl
use strict;
use warnings;
use XML::Simple;
my $xml = <<'EOX';
NG171TDCUAD
\\NG171TDCUAD\D: Data
23/11/2005 22:58:03
13,567,900,093
33minutesand52seconds
382 MB/min
EOX
my $p = XML::Simple->new;
my $r = $p->XMLin ($xml);
print "$_:\t$r->{$_}\n" for grep m/time/i => keys %$r;
-->8---
# perl test.pl
ElapsedTime: 33minutesand52seconds
StartTime: 23/11/2005 22:58:03
Enjoy, Have FUN! H.Merijn
--8<--- test.pl
#!/pro/bin/perl
use strict;
use warnings;
use XML::Simple;
my $xml = <<'EOX';
EOX
my $p = XML::Simple->new;
my $r = $p->XMLin ($xml);
print "$_:\t$r->{$_}\n" for grep m/time/i => keys %$r;
-->8---
# perl test.pl
ElapsedTime: 33minutesand52seconds
StartTime: 23/11/2005 22:58:03
Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2008 12:28 AM
01-04-2008 12:28 AM
Re: Need Help In Writing Perl Code
While it is tempting to parse HTML and XML with regular expressions, please try to avoid it, as you will hit every possible problem you thought could never happen somewhere along the line when the project evolves.
--8<--- test.pl
#!/pro/bin/perl
use strict;
use warnings;
use XML::Simple;
my $xml = <<'EOX';
NG171TDCUAD
\\NG171TDCUAD\D: Data
23/11/2005 22:58:03
13,567,900,093
33minutesand52seconds
382 MB/min
EOX
my $p = XML::Simple->new;
my $r = $p->XMLin ($xml);
print "$_:\t$r->{$_}\n" for grep m/time/i => keys %$r;
-->8---
# perl test.pl
ElapsedTime: 33minutesand52seconds
StartTime: 23/11/2005 22:58:03
Enjoy, Have FUN! H.Merijn
--8<--- test.pl
#!/pro/bin/perl
use strict;
use warnings;
use XML::Simple;
my $xml = <<'EOX';
EOX
my $p = XML::Simple->new;
my $r = $p->XMLin ($xml);
print "$_:\t$r->{$_}\n" for grep m/time/i => keys %$r;
-->8---
# perl test.pl
ElapsedTime: 33minutesand52seconds
StartTime: 23/11/2005 22:58:03
Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP