Fwd: Is it a perl Bug?

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default Fwd: Is it a perl Bug?



    Tom Franklyn <tomfranklyn@hotmail.com> wrote:From: "Tom Franklyn"
    Subject: Is it a perl Bug?
    Date: Wed, 04 Feb 2004 12:43:56 +0200

    Dear all,

    I've following code :

    ==========
    #!/usr/bin/perl

    my $a = "ab:cd:ef";
    my @b = split(/:/,$a);
    print ("@b\n");

    my @c = ('/:/', $a);
    my @d = split(@c);
    print ("@d\n");
    ===========
    Whats wrong with my code?
    why @b and @d give different output?

    Rgds,
    Tom Franklyn
    ------------------------------------------------------------
    Jesus?? Not a God!
    [url]http://www.geocities.com/abdlfth99/jesus_not_a_god.htm[/url]




    ---------------------------------
    Do you Yahoo!?
    Yahoo! SiteBuilder - Free web site building tool. Try it!
    Nancy Clark Guest

  2. Similar Questions and Discussions

    1. Off Topic: Active Perl Native Windows / cygwin perl
      I have both activestate windows native perl installed and the default cygwin perl. How can I have the cygwin shell use the windows perl rather...
    2. Control a non-perl image viewer from perl script
      Below is a (non-finished) script that trys to run a linux viewer called eog (eye of gnome) in a script that will eventually allow me to power thru...
    3. Re : Installing CPAN Perl Modules with Activestate Perl 5. v5.8
      Hi, In the process of trying to get perl modules installed, I downloaded over 300 Activestate specific perl modules and they work fine (of the ones...
    4. Effeciency question - perl scripts v's perl exe's
      Max Adams wrote: The only existing Perl compiler is part of perl. Anything else is just a packager that puts a perl, required modules, and the...
    5. Designing Interfaces with Perl and Perl APIs
      Hi, I am a long date perl programmer, and from time to time, I am having the same trouble: - To design interfaces for a self contained...
  3. #2

    Default Re: Fwd: Is it a perl Bug?

    On Wednesday 04 February 2004 10:48 am, nancy clark wrote:
    > Tom Franklyn <tomfranklyn@hotmail.com> wrote:From: "Tom Franklyn"
    > Subject: Is it a perl Bug?
    > Date: Wed, 04 Feb 2004 12:43:56 +0200
    >
    > Dear all,
    >
    > I've following code :
    >
    > ==========
    > #!/usr/bin/perl
    >
    > my $a = "ab:cd:ef";
    > my @b = split(/:/,$a);
    > print ("@b\n");
    >
    > my @c = ('/:/', $a);
    > my @d = split(@c);
    What exactly are you wanting to happen here?

    What you're actualy doing is calling

    split(/ab/,'cd','ef');

    which says use 'ab' as the pattern,'cd' as the expr, and 'ef' as the limit.

    split obviously can't handle this and thus returns undef.

    > print ("@d\n");
    > ===========
    > Whats wrong with my code?
    > why @b and @d give different output?
    >
    > Rgds,
    > Tom Franklyn
    > ------------------------------------------------------------
    > Jesus?? Not a God!
    > [url]http://www.geocities.com/abdlfth99/jesus_not_a_god.htm[/url]
    >
    >
    >
    >
    > ---------------------------------
    > Do you Yahoo!?
    > Yahoo! SiteBuilder - Free web site building tool. Try it!
    --
    Gary Stainburn

    This email does not contain private or confidential material as it
    may be snooped on by interested government parties for unknown
    and undisclosed purposes - Regulation of Investigatory Powers Act, 2000

    Gary Stainburn Guest

  4. #3

    Default Re: Is it a perl Bug?

    Nancy Clark wrote:
    >
    > Tom Franklyn <tomfranklyn@hotmail.com> wrote:From: "Tom Franklyn"
    > Subject: Is it a perl Bug?
    > Date: Wed, 04 Feb 2004 12:43:56 +0200
    >
    > Dear all,
    >
    > I've following code :
    >
    > ==========
    > #!/usr/bin/perl
    >
    > my $a = "ab:cd:ef";
    > my @b = split(/:/,$a);
    > print ("@b\n");
    >
    > my @c = ('/:/', $a);
    > my @d = split(@c);
    > print ("@d\n");
    > ===========
    > Whats wrong with my code?
    > why @b and @d give different output?
    Hi Tom, Nancy.

    Two problems here. First of all

    my @c = ('/:/', $a)

    should be either

    my @c = (':', $a)
    or
    my @c = (qr/:/, $a)

    otherwise the regex would match the three characters
    slash, colon, slash.

    Secondly, 'split' is prototyped, so it forces its first
    parameter into scalar context. Array @c has two elements
    so your call

    my @d = split(@c)

    is equivalent to

    my @d = split(2)

    which will try to split $_ on the regex '2'.

    Look at this code:

    $_ = "ab2cd2ef";
    my @c = (1, 2);
    my @d = split(@c);
    print ("@d\n");

    **OUTPUT

    ab cd ef

    HTH,

    Rob


    Rob Dixon Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139