Professional Web Applications Themes

String concatenation with .= <FH> - PERL Miscellaneous

[email]powell_lukehotmail.com[/email] (Luke Powell) wrote: : I found that when I did this: : : $record .= <FH>; #replaces rather than appends to $record : : that my record would not be concatenated with the the output of <FH>, : it would be replaced. Not seeing it happen. #!perl $record = 'foo'; $record .= <DATA>; print $record; # prints "foobar\n" __DATA__ bar Have you got a short, complete program that demonstrates the phenomenon?...

  1. #1

    Default Re: String concatenation with .= <FH>

    [email]powell_lukehotmail.com[/email] (Luke Powell) wrote:

    : I found that when I did this:
    :
    : $record .= <FH>; #replaces rather than appends to $record
    :
    : that my record would not be concatenated with the the output of <FH>,
    : it would be replaced.

    Not seeing it happen.

    #!perl
    $record = 'foo';
    $record .= <DATA>;
    print $record; # prints "foobar\n"
    __DATA__
    bar

    Have you got a short, complete program that demonstrates the
    phenomenon?

    Jay Tilton Guest

  2. #2

    Default Re: String concatenation with .= <FH>

    [email]powell_lukehotmail.com[/email] (Luke Powell) wrote in message news:<e7ccbaac.0307081353.527d24e5posting.google. com>...
    > I was writing a program to p some data and I found something odd.
    > I'm using the ActiveState 5.8.0 for Windows (build 804) version of
    > Perl, and I found that when I did this:
    >
    > $record .= <FH>; #replaces rather than appends to $record
    >
    Could you post a very small script that shows this?
    I couldn't reproduce what you describe above. (although Im using 5.6.1)
    Here is what I tried:

    use strict;
    use warnings;
    open(F,"<$0") || die $!;
    my $record = "first line\n";
    $record .= <F>;
    print "record = ",$record,"\n";

    Its output was:
    record = first line
    use strict;
    > that my record would not be concatenated with the the output of <FH>,
    > it would be replaced. That was odd so I tried this:
    >
    > $record .= $_ = <FH>; #acts right and appends to $record
    >
    > and that worked like a champ. Finally I tried:
    >
    > $record = $record . <FH>; #also acts right, appends to $record
    >
    > and I found that worked as well. So my question is why did my original
    > form not work when the other two did? Could anybody explain this to a
    > Perl newbie?
    >
    > Thanks,
    >
    > Luke Powell
    > [email]powell_lukehotmail.com[/email]
    Bryan Castillo Guest

  3. #3

    Default Re: String concatenation with .= <FH>

    [email]rook_5150[/email] (Bryan Castillo) wrote in message news:<1bff1830.0307082117.49fd08a1posting.google. com>...
    > [email]powell_lukehotmail.com[/email] (Luke Powell) wrote in message news:<e7ccbaac.0307081353.527d24e5posting.google. com>...
    > > I was writing a program to p some data and I found something odd.
    > > I'm using the ActiveState 5.8.0 for Windows (build 804) version of
    > > Perl, and I found that when I did this:
    > >
    > > $record .= <FH>; #replaces rather than appends to $record
    > >
    >
    > Could you post a very small script that shows this?
    > I couldn't reproduce what you describe above. (although Im using 5.6.1)
    > Here is what I tried:
    >
    > use strict;
    > use warnings;
    > open(F,"<$0") || die $!;
    > my $record = "first line\n";
    > $record .= <F>;
    > print "record = ",$record,"\n";
    >
    > Its output was:
    > record = first line
    > use strict;
    >
    Sure Brian... This actually made me investigate the problem a little
    more closely, so I can be a little more specific about the cause. It
    appears to only be a problem when I use $/ = \4 to make it a fixed
    record length mode. Here's the script:

    use strict;
    use warnings;
    open(FH,"temp.txt");
    $/=\5
    my $string="This ";
    $string.=<FH>;
    print $string;

    temp.txt contains:
    works

    This outputs:
    works

    Thanks for your replying :).

    Luke
    Luke Powell Guest

  4. #4

    Default Re: String concatenation with .= <FH>

    [email]powell_lukehotmail.com[/email] (Luke Powell) wrote in message news:<e7ccbaac.0307111514.1e0a8253posting.google. com>...
    > [email]rook_5150[/email] (Bryan Castillo) wrote in message news:<1bff1830.0307082117.49fd08a1posting.google. com>...
    > > [email]powell_lukehotmail.com[/email] (Luke Powell) wrote in message news:<e7ccbaac.0307081353.527d24e5posting.google. com>...
    > > > I was writing a program to p some data and I found something odd.
    > > > I'm using the ActiveState 5.8.0 for Windows (build 804) version of
    > > > Perl, and I found that when I did this:
    > > >
    > > > $record .= <FH>; #replaces rather than appends to $record
    > > >
    > >
    > > Could you post a very small script that shows this?
    > > I couldn't reproduce what you describe above. (although Im using 5.6.1)
    > > Here is what I tried:
    > >
    > > use strict;
    > > use warnings;
    > > open(F,"<$0") || die $!;
    > > my $record = "first line\n";
    > > $record .= <F>;
    > > print "record = ",$record,"\n";
    > >
    > > Its output was:
    > > record = first line
    > > use strict;
    > >
    >
    > Sure Brian... This actually made me investigate the problem a little
    > more closely, so I can be a little more specific about the cause. It
    > appears to only be a problem when I use $/ = \4 to make it a fixed
    > record length mode. Here's the script:
    >
    > use strict;
    > use warnings;
    > open(FH,"temp.txt");
    > $/=\5
    $/=\5; # <- forgot semi-colon
    > my $string="This ";
    > $string.=<FH>;
    > print $string;
    >
    > temp.txt contains:
    > works
    >
    > This outputs:
    > works
    >
    Im seeing the same problem for 5.8.0, on Windows98 and Free BSD 5.0. Using
    5.6.1, Im getting the expected results.

    I'm thinking this is a bug in 5.8.0.

    > Thanks for your replying :).
    >
    > Luke
    Bryan Castillo Guest

Similar Threads

  1. string concatenation
    By Rinoa in forum Macromedia ColdFusion
    Replies: 1
    Last Post: April 22nd, 01:05 PM
  2. String concatenation qn
    By Wolf Blaum in forum PERL Beginners
    Replies: 4
    Last Post: January 26th, 12:21 PM
  3. uninitialized string concatenation?
    By Lonewolf in forum PERL Beginners
    Replies: 1
    Last Post: September 9th, 02:20 PM
  4. Replies: 5
    Last Post: September 7th, 11:02 PM
  5. String Concatenation Bug
    By ecow in forum PHP Development
    Replies: 1
    Last Post: August 18th, 02:14 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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