Sponsored Content
Top Forums Shell Programming and Scripting Matching - Quick Perl Question Post 302820503 by spacebar on Wednesday 12th of June 2013 07:25:58 PM
Old 06-12-2013
Try something like this which uses the "smart match" to perform a "in list":
Code:
use strict;
use warnings;

my @months =  ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
my $file   =  'sample1.xyt';


open my $info, $file or die "Could not open $file: $!";
while ( <$info> ) {
  chomp;
  my @cols   =  split(" ");
  if ( $cols[1] ~~ @months ) {
    print "Valid month found: $cols[1]\n";
  } else {
    print "Invalid month found: $cols[1]\n";
  }
}

arrays - Perl: if ( element in list ) - Stack Overflow

Last edited by Scott; 06-12-2013 at 08:29 PM.. Reason: Removed FONT tag AGAIN
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

A very quick question

Just a super quick question: how do you put a link in your php code. I want to make a link to something in /tmp directory. i.e. how do you put a href into php, I think it's done a bit differently. thanks john (1 Reply)
Discussion started by: jmg5
1 Replies

2. Shell Programming and Scripting

Quick perl question

Hey everyone, I am a newbie with perl, and I just have a quick question that may seem really stupid. Like I said, I'm new, so please bear w/ me :) I'm trying to make a really simple program where there are two inputs. First one is just a string, and the next one is a number. Once the user... (7 Replies)
Discussion started by: jason_v
7 Replies

3. Shell Programming and Scripting

pattern matching + perl question

i can only find the first occurance of a pattern how do i set it to loop untill all occurances have changed. #! /usr/bin/perl use POSIX; open (DFH_FILE, "./dfh") or die "Can not read file ($!)"; foreach (<DFH_FILE>) { if ($_ !~ /^#|^$/) { chomp; ... (1 Reply)
Discussion started by: Optimus_P
1 Replies

4. UNIX for Dummies Questions & Answers

quick question

from command prompt I did grep two words on a same line for eg: grep abc | grep xyz and I got tht particular line, but I want to know when I vi that file how to directly search for that particular line? I appreciate if any one can provide answer, thanks in advance (2 Replies)
Discussion started by: pkolishetty
2 Replies

5. Shell Programming and Scripting

[B]Perl sort quick question[/B]

I've done a quick Google about this, but could not find the answer I want. Say, there is an array like this: @A = qw(cd1 a1 ef a2 hij a12 b2 b4 b22); I want to sort the array in the first order: @sorted = qw(a1 a12 a2 b2 b22 b4 cd1 ef hij); And second order: @sorted = qw(a1 a2 a12 b2 b4... (5 Replies)
Discussion started by: zx1106
5 Replies

6. Shell Programming and Scripting

quick question

I am using sed to find a pattern in a line and then I want to retain the pattern + the rest of the line. How is this possible? ie: line is: 14158 05-15-08 20:00 123-1234-A21/deliverable/dhm.a search for 123-1234-A21 ie: echo $line | sed 's/.*\(\{3\}-\{4\}-\{3\}\{5\}\).*/\1/' ... (1 Reply)
Discussion started by: phreezr
1 Replies

7. Shell Programming and Scripting

Quick question

When I have a file like this: 0084AF aj-123-a NAME Ajay NAME Kumar Engineer 015ED6 ck-345-c 020B25 ef-456-e 027458 pq-890-p NAME Peter NAME Salob Doctor 0318F0 xy-123-x NAME Xavier Arul NAME Yesu Supervisor 0344CA de-456-d where - The first NAME is followed by... (6 Replies)
Discussion started by: ajay41aj
6 Replies

8. Shell Programming and Scripting

PERL - another quick hash of hashes question

Hi, sorry, two hash related questions in one day .. but this has got me a bit stuck. I have a mysql database table that kind of looks like this, the table is called "view1" and a snippet of that table (SELECT'ing just rows with serial number 0629AN1200) is below serial nic_name ... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

9. UNIX for Dummies Questions & Answers

Quick question

Hi guys Quick question Im creating an FTP server and im chrooting each user to there home directory blah blah. Ive also setup scponly so there locked etc. Im a novice at unix and have just reaslised the primary group of scponly is the username of one of the ftp users... which im sure... (1 Reply)
Discussion started by: mokachoka
1 Replies

10. UNIX for Dummies Questions & Answers

Perl Pattern Matching Question

Hi all, I have a pattern matching problem in which i'm not sure how to attack. Here is my problem: I have a list of strings that appear in the following format: String: LE_(1234 ABC)^2^ABC^DEFG What i need to do is replace all the characters after the first ^ with blank. So the output... (2 Replies)
Discussion started by: WongSifu
2 Replies
xscreensaver-text(1)						XScreenSaver manual					      xscreensaver-text(1)

NAME
xscreensaver-text - prints some text to stdout, for use by screen savers. SYNOPSIS
xscreensaver-text [--verbose] [--columns N] [--text STRING] [--file PATH] [--program CMD] [--url URL] DESCRIPTION
The xscreensaver-text script prints out some text for use by various screensavers, according to the options set in the ~/.xscreensaver file. This may dump the contents of a file, run a program, or load a URL. OPTIONS
xscreensaver-text accepts the following options: --columns N or --cols N Where to wrap lines; default 72 columns. --verbose or -v Print diagnostics to stderr. Multiple -v switches increase the amount of output. Command line options may be used to override the settings in the ~/.xscreensaver file: --string STRING Print the given string. It may contain % escape sequences as per strftime(2). --file PATH Print the contents of the given file. If --cols is specified, re-wrap the lines; otherwise, print them as-is. --program CMD Run the given program and print its output. If --cols is specified, re-wrap the output. --url HTTP-URL Download and print the contents of the HTTP document. If it contains HTML, RSS, or Atom, it will be converted to plain-text. Note: this re-downloads the document every time it is run! It might be considered abusive for you to point this at a web server that you do not control! ENVIRONMENT
HTTP_PROXY or http_proxy to get the default HTTP proxy host and port. BUGS
The RSS and Atom output is always ISO-8859-1, regardless of locale. URLs should be cached, use "If-Modified-Since", and obey "Expires". SEE ALSO
xscreensaver-demo(1), xscreensaver(1), fortune(1), phosphor(1), apple2(1), starwars(1), fontglide(1), dadadodo(1), webcollage(1), http://www.livejournal.com/stats/latest-rss.bml, http://twitter.com/statuses/public_timeline.atom, driftnet(1), EtherPEG, EtherPeek COPYRIGHT
Copyright (C) 2005 by Jamie Zawinski. Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. AUTHOR
Jamie Zawinski <jwz@jwz.org>, 20-Mar-2005. X Version 11 5.15 (28-Sep-2011) xscreensaver-text(1)
All times are GMT -4. The time now is 11:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy