Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>FINAL POST FOR THIS QUESTION:</strong> Based on your latest updates, I believe the following code illustrates how there is no problem with using <code>/:/</code> as the first argument to <code>split</code>. It also points out that it is easier to read code when one uses arguments to functions rather than relying on global variables:</p> <pre><code>#!/usr/bin/perl use strict; use warnings; use Data::Dumper; for my $varname ( qw( adntopr.cpr.smtref.actv cpr_operator_detail )) { print $varname, "\n"; print Dumper get_columns(\*DATA, $varname); } sub get_columns { my ($input_fh, $varname) = @_; while ( my $line = &lt;$input_fh&gt; ) { chomp $line; my @values = split /=&gt;/, $line; next unless $varname eq $values[0]; return [ split /:/, $values[1] ]; } return; } __DATA__ adntopr.cpr.smtref.actv=&gt;3:8:18:29:34:38:46:51:53:149 adntopr.smtsale2=&gt;3:8:16:22:27:37:39:47:52:57:62:82:102:120:138:234:239:244:249:250:259:262:277:282:287:289:304:319:327:331:335:339:340:341:342:353:364:375:386:397:408 cpr_operator_detail=&gt;3:11:18:28:124:220:228:324 cpr_operator_org_unit_map=&gt;7:12 cpr_operator_metric_actual=&gt;8:15:25:33:38:40:51 C:\Temp&gt; tjm adntopr.cpr.smtref.actv $VAR1 = [ '3', '8', '18', '29', '34', '38', '46', '51', '53', '149' ]; cpr_operator_detail $VAR1 = [ '3', '11', '18', '28', '124', '220', '228', '324' ]; </code></pre> <p>There is a lot of cruft in that code. Here is my interpretation of what you are trying to do:</p> <p><strong>UPDATE:</strong> Given your recent remark about regex special characters in patterns, if you are going to use them in the pattern to split, make sure to quote them. There is also a chance that <code>$ETLSpliter::name</code> might contain other special characters. I modified the code to deal with that possibility.</p> <pre><code>sub getColumns { open my $input, '&lt;', $ETLSpliter::configFile or die "Error opening '$ETLSpliter::configFile': $!"); my @columns; while( my $conline = &lt;$input&gt; ) { my @values = split /=&gt;/, $conline; print "not at: ".$conline; push @columns, $values[1] if $values[0] =~ /\Q$ETLSpliter::name/; } return @columns; } </code></pre> <p><strong>ANOTHER UPDATE:</strong></p> <p>So, the pattern indeed is <code>/=&gt;/</code> based on your comment below. Then:</p> <pre><code>my $conline = q{cpr_operator_detail=&gt;3:11:18:28:124:220:228:324}; my @values = split /=&gt;/, $conline; use Data::Dumper; print Dumper \@values; __END__ C:\Temp&gt; tml $VAR1 = [ 'cpr_operator_detail', '3:11:18:28:124:220:228:324' ]; </code></pre> <p><strong><em>No errors</em> ... <em>No warnings</em></strong> Therefore, there is something else that is going on which you insist on not showing us.</p> <p><strong>Other Remarks:</strong></p> <ol> <li><p>Use lexical filehandles and let perl tell you what errors it may encounter rather than presuming.</p></li> <li><p>Declare variables in the smallest applicable scope.</p></li> <li><p>No need to assign <code>$_</code> to <code>$conline</code> in the body of the loop when you can do that in the <code>while</code> statement.</p></li> <li><p>In the original code, you were not putting anything in <code>@columns</code> or doing anything useful with <code>$colData</code>.</p></li> <li><p>Tone down the rhetoric. Computers work on the principle of GIGO.</p></li> <li><p>Looking at the code at <a href="http://wtfperl.pastebin.com/m418137f9" rel="nofollow noreferrer">the link you posted</a>, it looks like you are not aware that you can do:</p> <pre><code>use File::Spec::Functions qw( catfile ); ... catfile($ETLSpliter::filepath_results, $ETLSpliter::actual_name); </code></pre></li> </ol> <p>Further, it looks like you are using a package where hash would have done the job:</p> <pre><code>$ETLSpliter{filepath} </code></pre> <p>Finally, you do realize <code>Spliter</code> is incorrect. ITYM: <code>Splitter</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload