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

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.
  • Comment on Re^2: do does not read massive containing element w/ ' sign.

Replies are listed 'Best First'.
Re^3: do does not read massive containing element w/ ' sign.
by 1nickt (Canon) on Aug 22, 2015 at 13:46 UTC

    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.

        "...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»