Sponsored Content
Top Forums Shell Programming and Scripting Perl help in deleting array that contains 0 Post 302542166 by yazu on Wednesday 27th of July 2011 12:24:51 AM
Old 07-27-2011
Ok, I'll try but my English is not good at all.

Perl switches (perldoc perlrun):
"-n" reads lines from @ARGV (that is INPUTFILE) to $_ and "-l" removes and adds (when printing) newline chars. "-a" splits $_ to @F array according to a regex from "-F" option

"grep {! RE} @F" filters all elements from the array (elements are strings - "{123, 0, 111}" and so on) where it's not true that 0 is a "word" (not in any numbers like 10, 101, etc.).

Then we join the ready list to a string with ", " as the separator and print it.

Last edited by yazu; 07-27-2011 at 01:33 AM..
This User Gave Thanks to yazu For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies

2. UNIX for Dummies Questions & Answers

Deleting Array Elements

Hi, I am writing a BASH shell script. I have an array that will contain IN ANY ORDER the following elements: DAY 8D MO NS. I would like to erase the element DAY, but since the order of the elements in the array are random, I will not know which element # DAY is (ie it's not as simple as... (3 Replies)
Discussion started by: msb65
3 Replies

3. Shell Programming and Scripting

deleting certain parts of a line in perl

I have a filr data.txt. Its contents are Available labels (* indicates activated, I indicates installed, R idicates running): abc-3.0.3 def-3.0.4 xyz-3.1.2-1.0 I want to delete " Available labels (* indicates activated, I indicates installed, R idicates running):" and... (3 Replies)
Discussion started by: lassimanji
3 Replies

4. Shell Programming and Scripting

perl -write values in a file to @array in perl

Hi can anyone suggest me how to write a file containing values,... say 19 20 21 22 .. 40 to an array @array = (19, 20, ... 40) -- Thanks (27 Replies)
Discussion started by: meghana
27 Replies

5. Shell Programming and Scripting

Perl grep array against array

Hi, Is there any way I can grep an array against another array? Basically here's what I need to do. There will be an array containing some fixed texts and I have to check whether some files contain these lines. Reading the same files over and over again for each different pattern doesnt seem... (1 Reply)
Discussion started by: King Nothing
1 Replies

6. Shell Programming and Scripting

perl, put one array into many array when field is equal to sth

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d"); would like to split the @test array into two array: @test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d"); means search for 3rd filed. Thanks find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies

7. Shell Programming and Scripting

Deleting characters with sed,perl,awk

Input: :: gstreamer :: xine-lib :: xine-lib-extras Output should be: gstreamer xine-lib xine-lib-extras How can it be done with sed or perl? (12 Replies)
Discussion started by: cola
12 Replies

8. Shell Programming and Scripting

Array in Perl - Detect several file to be in one array

Hi everyone I have one question about using array in perl. let say I have several log file in one folder.. example test1.log test2.log test3.log and the list goes on.. how to make an array for this file? It suppose to detect log file in the current directory and all the log file will... (3 Replies)
Discussion started by: sayachop
3 Replies

9. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

10. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies
Test::Base::Filter(3pm) 				User Contributed Perl Documentation				   Test::Base::Filter(3pm)

NAME
Test::Base::Filter - Default Filter Class for Test::Base SYNOPSIS
package MyTestSuite; use Test::Base -Base; ... reusable testing code ... package MyTestSuite::Filter; use Test::Base::Filter -Base; sub my_filter1 { ... } DESCRIPTION
Filters are the key to writing effective data driven tests with Test::Base. Test::Base::Filter is a class containing a large default set of generic filters. You can easily subclass it to add/override functionality. FILTERS
This is a list of the default stock filters (in alphabetic order): append list => list Append a string to each element of a list. --- numbers lines chomp append=-# join one two three array list => scalar Turn a list of values into an anonymous array reference. base64_decode scalar => scalar Decode base64 data. Useful for binary tests. base64_encode scalar => scalar Encode base64 data. Useful for binary tests. chomp list => list Remove the final newline from each string value in a list. chop list => list Remove the final char from each string value in a list. dumper scalar => list Take a data structure (presumably from another filter like eval) and use Data::Dumper to dump it in a canonical fashion. escape scalar => scalar Unescape all backslash escaped chars. eval scalar => list Run Perl's "eval" command against the data and use the returned value as the data. eval_all scalar => list Run Perl's "eval" command against the data and return a list of 4 values: 1) The return value 2) The error in $@ 3) Captured STDOUT 4) Captured STDERR eval_stderr scalar => scalar Run Perl's "eval" command against the data and return the captured STDERR. eval_stdout scalar => scalar Run Perl's "eval" command against the data and return the captured STDOUT. exec_perl_stdout list => scalar Input Perl code is written to a temp file and run. STDOUT is captured and returned. flatten scalar => list Takes a hash or array ref and flattens it to a list. get_url scalar => scalar The text is chomped and considered to be a url. Then LWP::Simple::get is used to fetch the contents of the url. hash list => scalar Turn a list of key/value pairs into an anonymous hash reference. head[=number] list => list Takes a list and returns a number of the elements from the front of it. The default number is one. join list => scalar Join a list of strings into a scalar. Join Join the list of strings inside a list of array refs and return the strings in place of the array refs. lines scalar => list Break the data into an anonymous array of lines. Each line (except possibly the last one if the "chomp" filter came first) will have a newline at the end. norm scalar => scalar Normalize the data. Change non-Unix line endings to Unix line endings. prepend=string list => list Prepend a string onto each of a list of strings. read_file scalar => scalar Read the file named by the current content and return the file's content. regexp[=xism] scalar => scalar The "regexp" filter will turn your data section into a regular expression object. You can pass in extra flags after an equals sign. If the text contains more than one line and no flags are specified, then the 'xism' flags are assumed. reverse list => list Reverse the elements of a list. Reverse list => list Reverse the list of strings inside a list of array refs. slice=x[,y] list => list Returns the element number x through element number y of a list. sort list => list Sorts the elements of a list in character sort order. Sort list => list Sort the list of strings inside a list of array refs. split[=string|pattern] scalar => list Split a string in into a list. Takes a optional string or regexp as a parameter. Defaults to /s+/. Same as Perl "split". Split[=string|pattern] list => list Split each of a list of strings and turn them into array refs. strict scalar => scalar Prepend the string: use strict; use warnings; to the block's text. tail[=number] list => list Return a number of elements from the end of a list. The default number is one. trim list => list Remove extra blank lines from the beginning and end of the data. This allows you to visually separate your test data with blank lines. unchomp list => list Add a newline to each string value in a list. write_file[=filename] scalar => scalar Write the content of the section to the named file. Return the filename. yaml scalar => list Apply the YAML::Load function to the data block and use the resultant structure. Requires YAML.pm. AUTHOR
Ingy dA~Xt Net <ingy@cpan.org> COPYRIGHT
Copyright (c) 2006, 2011. Ingy dA~Xt Net. All rights reserved. Copyright (c) 2005. Brian Ingerson. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html perl v5.12.3 2011-04-04 Test::Base::Filter(3pm)
All times are GMT -4. The time now is 08:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy