The module xml::simple is not load
use XML::Simple;
You might need to install XML::Simple. Since you are new to Perl, the recommendation is to use another XML parser.
How format numbers (1246633 => 1 246 633)
From http://perldoc.perl.org/perlfaq5.html#How-can-I-output-my-numbers-with-commas-added%3f: Number::Format
| [reply] [d/l] |
| [reply] |
use Number::Format;
my $x = new Number::Format(-thousands_sep => ' ');
my $number = 1234567890;
print $x->format_number($number);
$ perl example.pl
1 234 567 890
You will need to install Number::Format from CPAN (see other answer)
You can also try this, but it does not take into account numbers with comma's:
my $number = 1234567890;
print format_number($number);
sub format_number{
my($x) = @_;
$x = reverse $x;
$x =~ s/(\d{3})/$1 /g;
$x = reverse $x;
return $x;
}
This prints:
1 234 567 890
| [reply] [d/l] [select] |
You can search for modules at .
| [reply] |
LWP (for "Library for WWW in Perl", also called libwww-perl) is a set of Perl modules that give Perl programming easy access to sending requests to the World Wide Web.
Howto update in Strawberry perl: open CPAN
perl -MCPAN -e shell
Search for a library, for example LWP:
i /libwww/
This gives you a list, you can install one (for me this is)
install GAAS/libwww-perl-5.837.tar.gz
You can also search for the XML::Simple
i /XML::Simple/
I get a list and I can install from:
install GRANTM/XML-Simple-2.20.tar.gz
Now you can type "exit" to get out of CPAN and try to use XML::Simple;
| [reply] [d/l] [select] |
Welcome to Perl and to the monastery Arenas,
powershell is not a programming language, so you probably can profit from some basic reading about Perl as the book Beginning Perl or the (old but still usefull) Perl Cookbook.
Some sparse suggestion being you new to Perl and using winz: you can check if you have a Perl's module installed with a simple oneliner (take a look at perldoc about command line switches)
perl -MNot::Installed::Module -e "1"
You are executing (-e) an always-return-true mini Perl program (what is inside the doublequote) but loading some module (after the -M ) before runnig the code. You obviosly get:
Can't locate Not/Installed/Module.pm in @INC (@INC contains:...
You can install modules using the cpanp client (working in the strawberry Perl distro on which DWimPerl is built)
cpanp -i Not::Installed::Module
Choose carefully module to install and use: XML::Simple is simply deprecated. Other modules are better but you need to learn how to use them: the following, working, code uses XML::Twig for xml parsing: anyway, even if you use a good module, xml parsing is a little triky and shaggy thing.
#!perl
use strict;
use warnings;
use XML::Twig;
my $t= XML::Twig->new(pretty_print => 'indented',
twig_handlers => {
'city/name'=>sub{ print $_[1]->text,"\n"; }
+,
'city/population'=>sub{ print "Pop: ",$_[1]
+->text,"\n"; },
}
);
$t->parseurl('http://athome.myminicity.com/xml');
__OUTPUT__
AtHome
Pop: 18998557
As last suggestion, when asking here at perlmonks, do your best to present a simple and fully understandable question, with code that reproduce the error you are facing, or being clear about data you have and data you want to get back from your program. Asking clear question let you to have in return good answers, sometimes real gems, lurking here very wise and experienced programmers (not me).
htH L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
| [reply] [d/l] [select] |
[int]$i = 99;
for($i=99; $i -gt 0; $i--) {
write-host $i " bottles of beer on the wall";
write-host $i " bottles of beer";
write-host "Take one down, pass it around"
write-host ($i-1) " bottles of beer on the wall"
write-host ""
}
Please see also rosettacode and monad.
Best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
| [reply] [d/l] |
Hello!
Many thanks to all of your help!
I will do: 'Choose carefully module'
Impossible to download 'Number::Format'
Probable my probleme is, I work with Vista 64
@htH = Artist:
I will also look for! => XML::Twig (great help!)
This is transforment from powershell (excel) script => html. Now i will change and us GDI files
http://arenas.pagesperso-orange.fr/mmc/simulation-athome-mmc.html
All files togeter
http://arenas.pagesperso-orange.fr/mmc/default-menu-Ville.html
Greting
@r
| [reply] |
Good Morning,
I have reinstall perl (\Dwim), and only one version!
So I m ready now.
Please: How selecte singelnode nestet with Twig.
and holdet by my $var =? (in the future so i can add math formula)
(With Shell was : $xbcom = (xml$xdxml).selectSingleNode("city/bases/@com").$xt)
How cleen variable: all or selective
Thanks @r
Nota bene:
I don't was able to install "format number". Regex is good to do.
my $VarNum = "14589965321"; # or "my $xbcom ="
$ins =~ s/(\d)(?=(\d{3})+(?!\d))/$1 /g;
print "$VarNum\n";
| [reply] [d/l] |
Also, please structure your questions a bit more.
...and welcome to PerlMonks. (bienvenido a PerlMonks)
| [reply] |