Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Help on 16/17/18/19/20 dot pl

by Raymond (Novice)
on Aug 09, 2013 at 20:06 UTC ( #1048838=perlquestion: print w/ replies, xml ) Need Help??
Raymond has asked for the wisdom of the Perl Monks concerning the following question:


Need help on the following codes, i couldn't solve
alone this ones, others i could fix them, thanks for your reply...
16.pl
#!/usr/bin/perl use strict; use warnings; use charnames ':short'; print "\N{greek:Delta} is an upper-case delta.\n"; #page 16 use charnames qw(cyrilic greek); print "\N{Sigma} and \N{Sigma} are Greek sigmas.\n"; print "\N{BE} and \N{be} are Cyrilic bes.\n";

No such script: 'CYRILIC' at 16.pl line 10.
Unknown charname 'BE' at 16.pl line 12.
Unknown charname 'be' at 16.pl line 12.
Wide character in print at 16.pl line 6.
+ is an upper-case delta.
Wide character in print at 16.pl line 11.
+ and + are Greek sigmas.
Wide character in print at 16.pl line 12.
+ and + are Cyrilic bes.

17.pl
#!/usr/bin/perl use strict; use warnings; use charnames ':short'; print "\N{greek:Delta} is an upper-case delta.\n"; #page 16 use charnames qw(cyrilic greek); print "\N{Sigma} and \N{Sigma} are Greek sigmas.\n"; print "\N{BE} and \N{be} are Cyrilic bes.\n";


Character U+00C4 (-) is named LATIN CAPITAL LETTER A WITH DIAERESIS
Wide character in printf at 17.pl line 10.
Character U+0394 (+) is named GREEK CAPITAL LETTER DELTA

18.pl
#!/usr/bin/perl use strict; use warnings; #use charnames qw(:full); my $name; my $code; my chr($code); #pagina 16 use charnames qw(:full); $name = "Music Sharp Sign"; $code = charnames::vianame($name); printf "%s is character U+%04X (%s)\n", $name, $code, chr($code);

No such class chr at 18.pl line 8, near "my chr"
BEGIN not safe after errors--compilation aborted at
18.pl line 11.

19.pl
#!/usr/bin/perl use strict; use warnings; my $string; my $char; my $seen; %seen = (); $string = "an apple a day"; foreach $char (slit //, $string) { $seen{$char}++; } print "unique chars are: ", short(keys %seen), "\n"; #pagina 17

Global symbol "%seen" requires explicit package name at 19.pl line 9.
syntax error at 19.pl line 11, near "//,"
Global symbol "%seen" requires explicit package name at
19.pl line 12.
Global symbol "%seen" requires explicit package name at 19.pl line 14.
Execution of 19.pl aborted due to compilation errors.

20.pl
#!/usr/bin/perl use strict; use warnings; my $string; my $seen; #pagina 18 %seen = (); $string = "an apple a day"; while ($string =~ /(.)/g) { $seen{$1}++; } #pagina 18 print "unique chars are: ", sort(keys %seen), "\n";

Global symbol "%seen" requires explicit package name at 20.pl line 9.
Global symbol "%seen" requires explicit package name at 20.pl line 12.
Global symbol "%seen" requires explicit package name at 20.pl line 15.
Execution of 20.pl aborted due to compilation errors.
Thanks people your answers made a diference.
"syntax error at 19.pl line 11, near "//,"" // is part of the program

Comment on Help on 16/17/18/19/20 dot pl
Select or Download Code
Re: Help on 16/17/18/19/20 dot pl
by McA (Curate) on Aug 09, 2013 at 20:29 UTC

    To your problem 20.pl

    You also have to declare %seen, so when you write my %seen = (); everything (related to this perl snippet) should be ok.

    UPDATE: The same with 19.pl

    Best regards
    McA

Re: Help on 16/17/18/19/20 dot pl
by Athanasius (Monsignor) on Aug 10, 2013 at 04:17 UTC

    Re: 16.pl:

    Except for the newlines (see note 3, below), this works for me (on Windows):

    #! perl use strict; use warnings; binmode STDOUT, ':utf8'; # OR: binmode STDOUT, ":encoding(UTF-8)" or die "Can't binmode to UTF- +8: $!"; # OR: use open qw( :encoding(UTF-8) :std ); use charnames ':short'; print "\N{greek:Delta} is an upper-case delta.\n"; use charnames qw(cyrillic greek); print "\N{Sigma} and \N{sigma} are Greek sigmas.\n"; print "\N{BE} and \N{be} are Cyrillic bees.\n";

    Output:

    14:08 >chcp 65001
    Active code page: 65001
    
    14:08 >perl 683_SoPW.pl
    Δ is an upper-case delta.
    
    Σ and σ are Greek sigmas.
    
    Б and б are Cyrillic bees.
    
    
    14:08 >
    

    Notes:

    1. “Cyrillic” has two letter Ls.

    2. You need to specify UTF8 for the output: see binmode.

    3. For some reason, newlines are printing double. I’ve tried printing \x0A, etc., but so far haven’t found any way to fix this. :-(

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: Help on 16/17/18/19/20 dot pl
by kcott (Abbot) on Aug 10, 2013 at 08:41 UTC

    G'day Raymond,

    "Wide character ..."

    I provided you with examples of ways to deal with this warning less than a fortnight ago; now you claim it's an issue you can't solve. Please go back and read what I wrote.

    "No such script: 'CYRILIC' ..."

    charnames shows "use charnames qw(cyrillic greek);". If you read the documentation, you should be able to fix this yourself.

    "Global symbol "%s" requires explicit package name"

    Search for that string in perldiag - Perl diagnostic messages to find out how to deal with it. I recommend you read perlintro - Perl introduction for beginners and use the diagnostics pragma while the meaning of these errors continues to elude you (they were explained to you in example 7.pl).

    "No such class chr at 18.pl line 8, near "my chr""

    Look at what you wrote at line 8; then look at the my documentation for the correct syntax.

    "syntax error at 19.pl line 11, near "//,""

    Look at line 11; then look near //. Can you spot the error?

    -- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1048838]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2014-10-31 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (225 votes), past polls