🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #9392

Re: Operación en un array en Perl

#9392
From: David SF
Date: Tue, 23 Jul 2002 22:27
40 lines
2026 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 23.07.2002, Eva Riart wrote in es.comp.os.linux.programacion

>  Como puedo hacer, de la forma m�s simple posible la siguiente operaci�n en
>  Perl?
>  
>               Dado un array de enteros:
>                                            my @array_de_enteros;
>  
>               y un string como el siguiente:
>  
>                                            $string="10,20,40-45,50";
>  
>               Obtener en @array_de_enteros=[10,20,40,41,42,43,44,45,50];

Llevo muy poco tiempo programando en perl, pero se me ocurre lo
siguiente:

    $str = "10,20,40-45,50";
    foreach (split /,/, $str) {
        if (/^(\d+)-(\d+)$/) {
            push @a, $_ for ($1..$2)
        } else {
            push @a, $_;
        }
    }
    print "@a";

A ver si te sirve..
Saludos.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9Pdg6J/HgPjz2jQERAvPnAJ4oKiHT3fH+MlRYnYjoERSX8tEBzgCdF+Q8
8jrEY5WAUOJhvbD/YI6i6c0=
=Lqdi
-----END PGP SIGNATURE-----
Technical Details
Message-ID: <q7lkha-837.ln@snowball.gotdns.org>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsmi-us.news.garr.it!newsmi-eu.news.garr.it!NewsITBone-GARR!fu-berlin.de!uni-berlin.de!156-leon-x11.libre.retevision.ES!not-for-mail
References: <ahk1f8$8j2$1@news.wanadoo.es>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,692681992ffe7fbf
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2002-07-23 15:30:18 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsmi-us.news.garr.it!newsmi-eu.news.garr.it!NewsITBone-GARR!fu-berlin.de!uni-berlin.de!156-leon-x11.libre.retevision.ES!not-for-mail
From: David SF <aktns@escomposlinux.org>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: Operación en un array en Perl
Date: Wed, 24 Jul 2002 00:27:06 +0200
Lines: 40
Message-ID: <q7lkha-837.ln@snowball.gotdns.org>
References: <ahk1f8$8j2$1@news.wanadoo.es>
NNTP-Posting-Host: 156-leon-x11.libre.retevision.es (62.83.242.156)
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: fu-berlin.de 1027463415 31122084 62.83.242.156 (16 [99261])
X-Orig-Path: snowball.gotdns.org!news
User-Agent: slrn/0.9.7.4 (Linux)