Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: putting text into array word by word

by jms53 (Monk)
on Jan 09, 2012 at 18:30 UTC ( #947050=note: print w/replies, xml ) Need Help??


in reply to Re: putting text into array word by word
in thread putting text into array word by word

Here is my full code:

#! /usr/bin/perl -w use strict; my $i = 0; my $element; my @words; my @all_words open FILE, "<", "input.txt" or die $!; print "file loaded \n"; while (<FILE>) { # the words from *this* line @words = split('', $_); push @all_words, @words; } print "table loaded \n"; foreach $element (@words) { print "$element"; }

the "file loaded" and "table loaded" messages appear, however the elements are not printed afterwards

Replies are listed 'Best First'.
Re^3: putting text into array word by word
by Eliya (Vicar) on Jan 09, 2012 at 18:44 UTC

    You also probably want split(' ', $_); (to split on whitespace), not split('', $_);.  Or simply split; (which has the same effect).

    BTW, your </code > tag doesn't work, because you have a space in between the angle bracket and the tag name...

Re^3: putting text into array word by word
by roboticus (Chancellor) on Jan 09, 2012 at 18:35 UTC

    jms53:

    Try printing from @all_words instead of @words.

    Update: s/allwords/all_words/, added code tags.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://947050]
help
Chatterbox?
[james28909]: ok maybe i need to ask this question in sopw and not CB but here goes
[james28909]: i am manually parsing html, and am trying to wrap my head around keeping up with tag counts
[james28909]: i can extract a certain tree manually by regexing the html file for a starting anchor, then i send the position of the match to a sub and then seek to that position in the file and keep up with div tags (for now)
[james28909]: how can i manage multiple tags? other than div?
[james28909]: i count the div and /div and when count == 0 it means i have got that nested tree

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2017-04-25 03:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (448 votes). Check out past polls.