Loading ...
Sorry, an error occurred while loading the content.

perl newbie qustions

Expand Messages
  • hellotexi
    $string = [11, 22, 33, 44]; print $$string[0] . n ; print @$string[0] . n ; output: 11 11 question: why @$string[0] works?
    Message 1 of 2 , Jun 16, 2012
    • 0 Attachment
      $string = [11, 22, 33, 44];

      print "$$string[0]" . "\n";


      print "@$string[0]" . "\n";



      output:
      11
      11



      question:
      why @$string[0] works?
    • Shawn H Corey
      ... Because it s a slice; see http://perldoc.perl.org/perldata.html#Slices Also, you should always `use strict;` and `use warnings`: #!/usr/bin/env perl use
      Message 2 of 2 , Jun 17, 2012
      • 0 Attachment
        On 12-06-16 09:20 PM, hellotexi wrote:
        >
        > $string = [11, 22, 33, 44];
        >
        > print "$$string[0]" . "\n";
        >
        > print "@$string[0]" . "\n";
        >
        > output:
        > 11
        > 11
        >
        > question:
        > why @$string[0] works?

        Because it's a slice; see http://perldoc.perl.org/perldata.html#Slices

        Also, you should always `use strict;` and `use warnings`:

        #!/usr/bin/env perl

        use strict;
        use warnings;

        my $string = [11, 22, 33, 44];

        print $$string[0], "\n";

        print @$string[0], "\n";

        __END__

        You do not need the quotes around variables unless you're embedding them
        in a string.


        --
        Just my 0.00000002 million dollars worth,
        Shawn

        Programming is as much about organization and communication
        as it is about coding.

        _Perl links_
        official site : http://www.perl.org/
        beginners' help : http://learn.perl.org/faq/beginners.html
        advance help : http://perlmonks.org/
        documentation : http://perldoc.perl.org/
        news : http://perlsphere.net/
        repository : http://www.cpan.org/
        blog : http://blogs.perl.org/
        regional groups : http://www.pm.org/
      Your message has been successfully submitted and would be delivered to recipients shortly.