Professional Web Applications Themes

multiline thingy in hash makes it single line item ? - PERL Miscellaneous

On 30 Jun 2003 18:58:27 -0700, Asim Suter <asimsuterhotmail.com> wrote: > Greetings! > > I read in a multiline variable from a file > setting $/ . I store the multiline variable in a hash. > > I do a split on newline on the multiline thingy stored in hash > and....... Why? Why join it first and then split it? > The whole multiline thingy is one-line thingy now.. :( > > > Does storing a multiline thing in a hash make it one line ? > > Can anyone syggest a workaround ? I have no idea what ...

  1. #1

    Default Re: multiline thingy in hash makes it single line item ?

    On 30 Jun 2003 18:58:27 -0700,
    Asim Suter <asimsuterhotmail.com> wrote:
    > Greetings!
    >
    > I read in a multiline variable from a file
    > setting $/ . I store the multiline variable in a hash.
    >
    > I do a split on newline on the multiline thingy stored in hash
    > and.......
    Why? Why join it first and then split it?
    > The whole multiline thingy is one-line thingy now.. :(
    >
    >
    > Does storing a multiline thing in a hash make it one line ?
    >
    > Can anyone syggest a workaround ?
    I have no idea what you're asking, or what you're trying to achieve.

    open(FH, "somefile") or die $!;

    To read the contents of a file in an array, with each record (by
    default each line) in an element:

    my lines = <FH>;

    If you want to get rid of the line (record) endings at the same time:

    chomp(my lines = <FH>);

    To read the content of a file into a single scalar

    my $lines;
    {
    local $/;
    $lines = <FH>;
    }
    > Kindly Cc [email]asimsuterhotmail.com[/email] in your replies.
    Post here, read here.
    > Snippet of stuff I am doing:
    >
    > $/ = "__END__" ;
    >
    > my lines = split /\n/ , $hash{$variable} ;
    Ok.... Now... Where is $hash{$variable} set? Where is $variable set?

    If I liberally interpret that code (hard to tell what exactly you're
    trying to do), I would probably guess that you're trying to do this:

    open(FH, "somefile") or die $!;
    my lines;
    while (<FH>)
    {
    last if /^__END__$/;
    push lines, $_;
    }


    Martien

    PS. Please, for next time, try to organise your thoughts. 90% of good
    programming is being able to express your problem and goal.
    --
    |
    Martien Verbruggen | I'm just very selective about what I accept
    Trading Post Australia | as reality - Calvin
    |
    Martien Verbruggen Guest

  2. #2

    Default Re: multiline thingy in hash makes it single line item ?

    Asim Suter <asimsuterhotmail.com> wrote:
    > Does storing a multiline thing in a hash make it one line ?

    No.

    > Can anyone syggest a workaround ?

    A workaround to what?

    Show us a complete program that we can run. Describe how its
    output is not what you want. Describe what output you do want.
    We will help you fix the code.

    > Kindly Cc [email]asimsuterhotmail.com[/email] in your replies.

    Kindly pick up the answers to your questions in the same
    place that you asked the questions.


    --
    Tad McClellan SGML consulting
    [email]tadmcaugustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

Similar Threads

  1. Single item Array Problem
    By drkshih in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: July 15th, 08:38 PM
  2. select line in multiline textfield?
    By bas@zinder.nl in forum Macromedia Flash
    Replies: 3
    Last Post: October 30th, 12:24 PM
  3. Replies: 1
    Last Post: April 16th, 08:44 PM
  4. Replies: 6
    Last Post: January 17th, 07:46 PM
  5. Add single item to number of files in one step
    By Mac McDougald in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 0
    Last Post: June 26th, 01:39 PM

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