Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: do does not read massive containing element w/ ' sign.

by marinersk (Priest)
on Aug 21, 2015 at 15:35 UTC ( [id://1139432]=note: print w/replies, xml ) Need Help??


in reply to «Do» does not read an array containing element w/ «'» sign.

I am unable to reproduce your issue.

Constructing a test data file from your snippet above:

'qweqwe', 'rtyr tyr', '\'asdasd', 'fghfghfgh'

And constructing a Perl script from your snippet:

use strict; use warnings; use Data::Dumper; open my $file, '<', 'test1.dat'; my @data=do $file; close $file; print Dumper \@data; exit; __END__

Produces:

D:\PerlMonks>read1.pl $VAR1 = [ undef ]; D:\PerlMonks>

This looks nothing like the problem you described.

I must be guessing wrong about what your script is doing. Please see How do I post a question effectively?

Replies are listed 'Best First'.
Re^2: do does not read massive containing element w/ ' sign.
by Anonymous Monk on Aug 21, 2015 at 15:43 UTC

    It would help if you used do properly...

    use strict; use warnings; use Data::Dumper; my @data=do 'test1.dat'; print Dumper \@data; __END__ $VAR1 = [ 'qweqwe', 'rtyr tyr', '\'asdasd', 'fghfghfgh' ];
      Excuse me, but could you please explain what is the proper way here -- as i see, you do the same i do, except you use that module Data? -- I have not hard coded the file name, nor did print it all out. So?
Re^2: do does not read massive containing element w/ ' sign.
by nikolay (Beadle) on Aug 22, 2015 at 09:44 UTC

    Thank you for your answer!

    I do that just like that, -- no open/close file:

    my @data=do $file;

    -- always worked for me until i got the string, containing _'_ sign.

      #!perl use strict; # in1.txt # '\'asdasd', 'fghfg, hfgh' my @data = do 'in1.txt'; print "$_\n" for @data;

      The above gives an output of

      'asdasd fghfg, hfgh

      Is the problem that you want this ?

      \'asdasd fghfg, hfgh
      poj
        Yes, but my @data had no data at all -- because do did not process the array right, having one element ' char. But have solved now w/ q~data~ -- so don't worry please on this. Thank you much!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1139432]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-23 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found