使用两个字符串在perl中使用chdir:chdir“ / home / $ dir1 / $ dir2”

时间:2019-12-09 17:32:18

标签: perl directory chdir

我有两个字符串:$dir1$dir2。我想使用chdir,如下所示:

chdir "/home/$dir1/$dir2";

当我尝试这样做时,它不会更改目录。我检查了当前工作目录,与以前一样

有什么办法吗?

1 个答案:

答案 0 :(得分:4)

通常我这样写:

import React, { useState, Fragment, useEffect } from 'react';

const parser = require('xml-js');

const RouteSelect = props => {
    const { routes } = props;

    const [selectedRouteName, setRouteName] = useState('');
    const [selectedRouteDirection, setRouteDirection] = useState('');

    //console.log(routes);

    const onChangeHandler = event => {

        setRouteName({ name: event.target.value });

        if(selectedRouteName.name) {
            getRouteDirection();
        }
    }
/*
    useEffect(() => {
        if(selectedRouteName) {
            getRouteDirection();
        }
    }); */

    const getRouteDirection = () => {

        const filteredRoute = routes.filter(route => route.Description._text === selectedRouteName.name);
        const num = filteredRoute[0].Route._text;

        let directions = [];
        fetch(`https://svc.metrotransit.org/NexTrip/Directions/${num}`)
            .then(response => { 
                return response.text();
            }).then(response => {
                return JSON.parse(parser.xml2json(response, {compact: true, spaces: 4}));
            }).then(response => {
                directions = response.ArrayOfTextValuePair.TextValuePair;
                // console.log(directions);
                setRouteDirection(directions);    
            })
            .catch(error => {
                console.log(error);
            });

            console.log(selectedRouteDirection); // This logged state is one value behind the selected option
    }

    const routeOptions = routes.map(route => <option key={route.Route._text}>{route.Description._text}</option>);

    return (
        <Fragment>
            <select onChange={onChangeHandler}>
                {routeOptions}
            </select>
        </Fragment>
    );
};

export default RouteSelect;

每当您对系统进行某些操作时,请检查结果以确保其发生。

而且,奇怪的是,我没有意识到我的书Effective Perl Programming的皮尔森的示例章节是the one that covers stacked file test operators