in reply to Re^2: do does not read massive containing element w/ ' sign.
in thread «Do» does not read an array containing element w/ «'» sign.

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.

Replies are listed 'Best First'.
Re^4: do does not read massive containing element w/ ' sign.
by nikolay (Beadle) on Aug 22, 2015 at 20:36 UTC

    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.

      "...i'm worrying about is its speed...the data is already in the script...what about tens of thousands of strings?"

      I assume you expect/want qweqwe rtyr tyr \'asdasd fghfghfgh as output, right?

      Perhaps it might be an alternative to write your data to a file as JSON with something like this:

      use JSON::XS; my $data = [qw( qweqwe rtyr tyr \'asdasd fghfghfgh)]; my $json = encode_json $data; # to file...

      Then process your data line by line as usual:

      #!/usr/bin/env perl use JSON::XS; use strict; use warnings; use feature qw (say); # use Data::Dump; open my $fh, '<', 'data.dat' or die $!; while ( my $line = <$fh> ) { chomp $line; say nikolay( decode_json($line) ); } close $fh; sub nikolay { my $data = shift; join " ", @$data; # what ever... } __END__ karls-mac-mini:monks karl$ ./json.pl qweqwe rtyr tyr \'asdasd fghfghfgh ...

      Please see also JSON::XS, JSON and Benchmark.

      Edit: Link added.

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

        Thank you, Karl, but i think it is a lot of overhead for my script at run time. -- Suppose to run nikolay sub. 10 000 times! -- How it is now -- i like because it is already in array (ready to use): to be fed to reg.exp.

        Alright, i think we can finish here. -- I have learned a lot from all the answers! -- And that would have impact on my future PERL development. Thank you all!