Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: extracting data from a file

by nithins (Sexton)
on Dec 14, 2012 at 07:21 UTC ( #1008787=note: print w/replies, xml ) Need Help??


in reply to extracting data from a file

moving each word in to a variable that too dynamically creating it during the run time is not possible by the best of knowledge i know

but u can dump it in to an hash which will create key value same as that of characters b/w " "

hope this code might help u

#!/usr/bin/perl use strict; use Data::Dumper; open ( FH ,'<' , 'D:\\myperlpgm\\nperl\\newfile.txt'); my %has; my @array; while(<FH>){ @array = split /"/; } print "@array\n"; for(@array){ $has{$_} = $_ ; } print Dumper ($has{ssss});

D:\\myperlpgm\\nperl\\newfile.txt contains -> "nithn""nnnn""ssss" data

Replies are listed 'Best First'.
Re^2: extracting data from a file
by davido (Archbishop) on Dec 14, 2012 at 08:58 UTC

    Huh?

    What is the hash for?

    And take a closer look at what's in @array. By changing "print "@array\n"; to "print Dumper @array;", you will see that @array contains extra elements that result from splitting on the quote character as if it were a simple delimiter rather than a balanced construct.

    Also, given the OP's data set, there's no reason for the $hash{ssss} element to even exist.

    This is a broken solution.


    Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008787]
help
Chatterbox?
[Your Mother]: :P
[LanX]: Moma knows best! ;-)
[Your Mother]: I am quite aware that Module::Build is MUCH more in favor with many monks but I had trouble with it every time I tried to use it and trouble with CPAN stuff that used it too.
[Your Mother]: Take my advice with a grain of salt. I haven't done a new CPAN release in years at this point.
[LanX]: I want to author a new module for CPAN w/o complicated build structure
[LanX]: ther is also Dist::Zilla :-/
[LanX]: How to make a CPAN Module Distribution from 2002
[Your Mother]: Dist::Zilla is kind of the nuclear option. I set it up back in the day but it's really targeted at authors who are managing MANY modules and want to automate everything.
[erix]: perlancar should know ;)
[LanX]: see warning

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2017-08-18 17:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (306 votes). Check out past polls.

    Notices?