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

So, question is, How i should store my data regarding sign _'_ ?

Your data is already in fields and in rows, so why not make it a CSV file?

$ cat 1139428.dat qweqwe,rtyr tyr,'asdasd,fghfghfgh foo,bar,baz,qux $
$ cat 1139428.pl #! perl use strict; use warnings; use Text::CSV_XS 'csv'; my $data = csv( in => '1139428.dat' ); foreach my $row ( @{ $data } ) { foreach my $field ( @{ $row } ) { print "$field\n"; } } __END__ $
$ perl 1139428.pl qweqwe rtyr tyr 'asdasd fghfghfgh foo bar baz qux $
The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: do does not read massive containing element w/ ' sign.
by nikolay (Beadle) on Aug 22, 2015 at 10:57 UTC
    I think it just makes my script more complicated at no worth: while moving by the array, i simply take by two elements, serially: 1,2 them 3,4 etc. So i have no need to organize the array as a table row/column. -- It is the first. The second is i do not go away from my problem w/ _'_ sign but simply change to another problem (w/ _,_ sing -- that i also has in my strings). So unless there is something i have missed from your suggestion, i see no reason to change things. For now i am focused on saving almost any character (in UTF-8) except TAB, CR etc and speed up my first parts of the pairs (of two elements) by writing them in the array as precompiled regexps.

      Yes, you missed at least a few things:

      1. Your data is already in rows and fields, so storing them (in the program) as an AoA, as is the output of Text::CSV_XS::csv() is actually the closest structure to your original. It does not make things more complicated. (I and others based this belief on your OP: "And here i get the problem: for example, the line from the file '\'asdasd', 'fghfghfgh' ")
      2. You are not the first programmer to have _'_ or _,_ in his data fields. Text::CSV_XS handles this (as does the universal CSV format) with quoting and escaping. Try reading the documentation for Text::CSV_XS which explains how to deal with your problem. For example you could use TAB as the field separator; CR already works as the record separator.
      3. In any case you would benefit from not having to write your own code to handle all possible combinations of characters and escape characters and double-escaped characters.
      4. Did you edit your post to state that you are planning to use alternate elements of the array as regexp to perform a substitution? I don't remember seeing that in your OP. If you did edit it, please make a note.
      5. If so, I hope you have been following the concurrent discussion on how to work with passing regexp into a program.
      Good luck, nikolay!

      The way forward always starts with a minimal test.

        Thank you for your time.

        1. the line from the file means my view on the data, and its actual organization. :o)

        2. It is awesome to use the module then -- the only point i'm worrying about is its speed -- w/ the array (as it is now in my script) the data is already in the script (in its array) while w/ the module it seems to me it has to be processed as yet (i.e. to be inputted into array) -- what about tens of thousands of strings? -- Please let know, if had such experience. -- It's better to know before doing! :o).

        3. Actually i've written the code already (this is from whence the _\'_ combination comes -- and it works only once: when adding new data to the file -- then, multiple times it works as is w/o checking/modification.

        4. I did not edit. but had noted that will use array elements as regexps -- but what does it change?

        5. No, i didn't see that, but i will go to read it. Thank you, again.